function MySetFileTime(sFileName:string;dtCreation,dtAccess,dtWrite:TDateTime):Boolean;
var
dft
Word;
ftCreation,ftLastAccess,ftLastWrite:TFileTime;
h:THandle;
File_Attributes : Integer ;
begin
//判断文件是否为只读属性,并且更改属性
File_Attributes:=FileGetAttr(sFileName) ;
//上一句话的API实现 File_Attributes:=GetFileAttributes(pchar(sFileName)) ;
if File_Attributes and faReadOnly <> 0 then
FileSetAttr(sFileName,File_Attributes - faReadOnly) ;
//上一句话的API实现 SetFileAttributes(pchar(sFileName),File_Attributes - faReadOnly) ;
h := CreateFile(PChar(sFileName), GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if h<>INVALID_HANDLE_VALUE then
begin
//时间转换
dft := DateTimeToFileDate(dtCreation) ;
DosDateTimeToFileTime(LongRec(dft).Hi,LongRec(dft).Lo,ftCreation) ;
dft := DateTimeToFileDate(dtAccess) ;
DosDateTimeToFileTime(LongRec(dft).Hi,LongRec(dft).Lo,ftLastAccess) ;
dft := DateTimeToFileDate(dtWrite) ;
DosDateTimeToFileTime(LongRec(dft).Hi,LongRec(dft).Lo,ftLastWrite) ;
//更改文件的属性为之前的状态
FileSetAttr(sFileName,File_Attributes) ;
end
else
result := False ;
//释放资源
Windows.CloseHandle(h) ;
end ;