使用什么函数能得到文件的日期和尺寸大小,很简单的问题(50分)

  • 主题发起人 主题发起人 西门
  • 开始时间 开始时间
西

西门

Unregistered / Unconfirmed
GUEST, unregistred user!
使用什么函数能得到文件的日期和尺寸大小,很简单的问题
例 c:/1.txt
 
function GetFileTimes(FileName : ShortString
typ : byte
var fDate : TDateTime) : Boolean;
var
fHandle : Integer;
fTimeC,fTimeA, fTimeM : TFileTime;
lTime : TFileTime;
sTime : TSystemTime;
begin
fHandle := FileOpen(FileName, fmShareDenyNone);
fDate := 0.0;
result := (fHandle >= 0);
if result then
begin
GetFileTime(fHandle, @fTimeC, @fTimeA, @fTimeM);
FileClose(fHandle);
case typ of
FD_CREATED : FileTimeToLocalFileTime(fTimeC, lTime);
FD_ACCESSED : FileTimeToLocalFileTime(fTimeA, lTime);
FD_MODIFIED : FileTimeToLocalFileTime(fTimeM, lTime);
end;
if FileTimeToSystemTime(lTime, sTime) then fDate := EncodeDate(sTime.wYear, sTime.wMonth, sTime.wDay) + EncodeTime(sTime.wHour, sTime.wMinute, sTime.wSecond, sTime.wMilliSeconds);
end;
end;

 
GetFileSize(filehandle,FileSize)
 
GetFileVersionInfo可以得到文件的所有信息
 
给你个例子:
function GetFileVersionInfomation(const FileName: string
var info: TFileInfo;UserDefine:string=''):
boolean;
const
SFInfo= '/StringFileInfo/';
var
VersionInfo: Pointer;
InfoSize: DWORD;
InfoPointer: Pointer;
Translation: Pointer;
VersionValue: string;
unused: DWORD;
begin
unused := 0;
Result := False;
InfoSize := GetFileVersionInfoSize(pchar(FileName), unused);
if InfoSize > 0 then
begin
GetMem(VersionInfo, InfoSize);
Result := GetFileVersionInfo(pchar(FileName), 0, InfoSize, VersionInfo);
if Result then
begin
VerQueryValue(VersionInfo, '/VarFileInfo/Translation', Translation, InfoSize);
VersionValue := SFInfo + IntToHex(LoWord(Longint(Translation^)), 4) +
IntToHex(HiWord(Longint(Translation^)), 4) + '/';
VerQueryValue(VersionInfo, pchar(VersionValue + 'CompanyName'), InfoPointer, InfoSize);
info.CommpanyName := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'FileDescription'), InfoPointer, InfoSize);
info.FileDescription := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'FileVersion'), InfoPointer, InfoSize);
info.FileVersion := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'InternalName'), InfoPointer, InfoSize);
info.InternalName := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'LegalCopyright'), InfoPointer, InfoSize);
info.LegalCopyright := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'LegalTrademarks'), InfoPointer, InfoSize);
info.LegalTrademarks := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'OriginalFileName'), InfoPointer, InfoSize);
info.OriginalFileName := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'ProductName'), InfoPointer, InfoSize);
info.ProductName := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'ProductVersion'), InfoPointer, InfoSize);
info.ProductVersion := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'Comments'), InfoPointer, InfoSize);
info.Comments := string(pchar(InfoPointer));
if VerQueryValue(VersionInfo, '/', InfoPointer, InfoSize) then
info.VsFixedFileInfo := TVSFixedFileInfo(InfoPointer^);
if UserDefine<>'' then
begin
if VerQueryValue(VersionInfo,pchar(VersionValue+UserDefine),InfoPointer,InfoSize) then
info.UserDefineValue:=string(pchar(InfoPointer));
end;
end;
FreeMem(VersionInfo);
end;
end;


 
function FileDateToDateTime(FileDate: Integer): TDateTime;
 
多人接受答案了。
 
后退
顶部