FileAge is not working with "c:\pagefile.sys"
Does anybody know why FileAge is not working with "c:\pagefile.sys"? It returns -1.
Update:
Found it: It is a Delphi bug fixed in Delphi 2010 (QC Entry 73539), but the PDF I have found does not explain how they fix it.Does anyone know how they fix it so I can fix my Delphi 7?
UPDA开发者_JS百科TE: Elegant fix provided by Radu Barbu!
Delphi 7, Win 7 (32 bits)
try this:
with a variable of type TSearchRec (wSr bellow) load pagefile.sys then
wSR.FindData.ftLastWriteTime
- should return when the file was accessed
and with the function bellow you should get the time
function FileTime2DateTime(FileTime: TFileTime): TDateTime;
var
LocalFileTime : TFileTime;
SystemTime : TSystemTime;
begin
Result := 0;
try
FileTimeToLocalFileTime(FileTime, LocalFileTime);
FileTimeToSystemTime(LocalFileTime, SystemTime);
Result := SystemTimeToDateTime(SystemTime);
except on e: Exception do
//some message if you want
end;
end;
best regards,
Note that FileAge is deprecated.
TFile.GetLastAccessTime( FileName)
might be a replacement...
Call GetLastError() to get the error code returned by FindFirstFile() API function (called by FileAge).
Update: Delphi 2010 fix falls back to FindFirstFile so most likely it won't help you. They call GetFileAttributesEx and if this fails, they call FindFirstFile. And GetFileAttributesEx is supposed to fail for pagefile.sys. So you do need to check the error code.
精彩评论