T
tdp
Unregistered / Unconfirmed
GUEST, unregistred user!
很奇怪,在有一台机器上,下面的函数返回成功,可修改时间会错1秒
比如:设置文件的修改时间为2007-1-8 16:42:5 结果为 2007-1-8 16:42:6
Function SetFileTime_LastWrite(FileName, lr_DateTime: string): Integer;
var
hFile : THandle;
WriteTime, LocalTime : TFILETIME;
SystemTime : TSystemTime;
begin
result:= 0;
try
hFile := FileOpen(FileName, fmOpenWrite or fmShareDenyNone);
if hFile <= 0 then
begin
result:= 1;
end else
begin
DateTimeToSystemTime(StrToDateTime(lr_DateTime), SystemTime);
SystemTimeToFileTime(SystemTime, LocalTime);
LocalFileTimeToFileTime(Localtime, WriteTime);
If not SetFileTime(hFile, nil, nil, @WriteTime) then
begin
result:= 2;
end;
end;
finally
FileClose(hFile);
end;
end;
比如:设置文件的修改时间为2007-1-8 16:42:5 结果为 2007-1-8 16:42:6
Function SetFileTime_LastWrite(FileName, lr_DateTime: string): Integer;
var
hFile : THandle;
WriteTime, LocalTime : TFILETIME;
SystemTime : TSystemTime;
begin
result:= 0;
try
hFile := FileOpen(FileName, fmOpenWrite or fmShareDenyNone);
if hFile <= 0 then
begin
result:= 1;
end else
begin
DateTimeToSystemTime(StrToDateTime(lr_DateTime), SystemTime);
SystemTimeToFileTime(SystemTime, LocalTime);
LocalFileTimeToFileTime(Localtime, WriteTime);
If not SetFileTime(hFile, nil, nil, @WriteTime) then
begin
result:= 2;
end;
end;
finally
FileClose(hFile);
end;
end;