[delphi函数]FileAge 获取文件的创建时间
2009-12-04 22:16 HYrz的菜园子 阅读(1178) 评论(0) 编辑 收藏 举报
function FileAge(const FileName: string): Integer;
{$IFDEF MSWINDOWS}
var
Handle: THandle;
FindData: TWin32FindData;
LocalFileTime: TFileTime;
begin
Handle := FindFirstFile(PChar(FileName), FindData);
if Handle <> INVALID_HANDLE_VALUE then
begin
Windows.FindClose(Handle);
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
if FileTimeToDosDateTime(LocalFileTime, LongRec(Result).Hi,
LongRec(Result).Lo) then Exit;
end;
end;
Result := -1;
end;
{$ENDIF}
{$IFDEF LINUX}
var
st: TStatBuf;
begin
if stat(PChar(FileName), st) = 0 then
Result := st.st_mtime
else
Result := -1;
end;
{$ENDIF}
{$IFDEF MSWINDOWS}
var
Handle: THandle;
FindData: TWin32FindData;
LocalFileTime: TFileTime;
begin
Handle := FindFirstFile(PChar(FileName), FindData);
if Handle <> INVALID_HANDLE_VALUE then
begin
Windows.FindClose(Handle);
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
if FileTimeToDosDateTime(LocalFileTime, LongRec(Result).Hi,
LongRec(Result).Lo) then Exit;
end;
end;
Result := -1;
end;
{$ENDIF}
{$IFDEF LINUX}
var
st: TStatBuf;
begin
if stat(PChar(FileName), st) = 0 then
Result := st.st_mtime
else
Result := -1;
end;
{$ENDIF}