我正在使用以下内容更改文本文件的创建日期:
using System.IO;
...
DateTime newCreate = new DateTime(year, month, day, hour, minutes, seconds);
File.SetCreationTime("changemydate.txt", newCreate);
Run Code Online (Sandbox Code Playgroud)
然而,这没有任何作用.没有错误消息,但它根本不会更改文件的日期.
我在Dropbox文件夹和随机文件夹中尝试了这个但没有成功
该DateTime newCreate对象似乎是正确的.
如果有人能指出我的想法,那就太好了......
Dmi*_*nko 24
实际上,每个文件有三个不同的时间:
要修改这些时间,您可以使用
File.SetCreationTime(path, time);
File.SetLastWriteTime(path, time);
File.SetLastAccessTime(path, time);
Run Code Online (Sandbox Code Playgroud)
分别.
看来,如果你想改变文件管理器(例如Explorer)中显示的文件日期,你应该尝试这样的事情:
String path = @"changemydate.txt";
DateTime time = new DateTime(year, month, day, hour, minutes, seconds);
if (File.Exists(path))
File.SetLastWriteTime(path, time);
Run Code Online (Sandbox Code Playgroud)