转帖
得到一个文件的创建日期,修改时
procedure TForm1.Button1Click(Sender: TObject);
var
FileOp : TOFStruct ;
FHandle : THandle ;
FInfo : TByHandleFileInformation ;
dtCreate,dtCreate2 : TSystemTime;
Temp:_FileTime;
begin
memo1.clear;
setlasterror(20);
FHandle:= openfile(pchar(edit1.text),FileOp ,OF_READ);
GetFileInformationByHandle(FHandle,FInfo);
memo1.Lines.Add('File Attributes : '+inttostr(FInfo.dwFileAttributes));
FileTimeToLocalFileTime(FInfo.ftCreationTime,Temp);
FileTimeToSystemTime(Temp,dtCreate);
memo1.Lines.Add('File Create Time : '
+inttostr(dtCreate.wYear)+'-'
+inttostr(dtCreate.wMonth)+'-'
+inttostr(dtCreate.wDay)+' '
+inttostr(dtCreate.wHour)+':'
+inttostr(dtCreate.wMinute)+':'
+inttostr(dtCreate.wSecond) );
FileTimeToLocalFileTime(FInfo.ftLastAccessTime,Temp);
FileTimeToSystemTime(Temp,dtCreate);
memo1.Lines.Add('File Last Access Time : '
+inttostr(dtCreate.wYear)+'-'
+inttostr(dtCreate.wMonth)+'-'
+inttostr(dtCreate.wDay)+' '
+inttostr(dtCreate.wHour)+':'
+inttostr(dtCreate.wMinute)+':'
+inttostr(dtCreate.wSecond) );
FileTimeToLocalFileTime(FInfo.ftLastWriteTime,Temp);
FileTimeToSystemTime(Temp,dtCreate);
memo1.Lines.Add('File Last Write Time : '
+inttostr(dtCreate.wYear)+'-'
+inttostr(dtCreate.wMonth)+'-'
+inttostr(dtCreate.wDay)+' '
+inttostr(dtCreate.wHour)+':'
+inttostr(dtCreate.wMinute)+':'
+inttostr(dtCreate.wSecond) );
memo1.Lines.Add('File Path and Name : '+FileOp.szPathName);
_lclose(FHandle);
end;