我有这个代码:
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, System.DateUtils, System.IOUtils;
var
fFileName: TFilename;
dtFileCreationTime, dtFileLastAccessTime, dtFileLastWriteTime: TTimeStamp;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
fFileName := 'myfilename.ext'; // here i insert correct path
dtFileCreationTime := DateTimeToTimeStamp(EncodeDateTime(1981, 10, 5, 20,
35, 40, 10));
dtFileLastAccessTime := DateTimeToTimeStamp(EncodeDateTime(1982, 11, 6, 21,
36, 41, 11));
dtFileLastWriteTime := DateTimeToTimeStamp(EncodeDateTime(1983, 12, 7, 22,
37, 42, 12));
TFIle.SetCreationTime(fFileName,
DateTimeToFileDate(TimeStampToDateTime(dtFileCreationTime)));
TFIle.SetLastAccessTime(fFileName,
DateTimeToFileDate(TimeStampToDateTime(dtFileLastAccessTime)));
TFIle.SetLastWriteTime(fFileName,
DateTimeToFileDate(TimeStampToDateTime(dtFileLastWriteTime)));
Writeln('FileCreationTime => ',
DateTimeToStr(TFIle.GetCreationTime(fFileName)));
Writeln('FileLastAccessTime => ',
DateTimeToStr(TFIle.GetLastAccessTime(fFileName)));
Writeln('FileLastWriteTime => ',
DateTimeToStr(TFIle.GetLastWriteTime(fFileName)));
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
只是我想设置文件的日期,但它不起作用,我在哪里犯了错误?感谢帮助。