delphi 如何删除文件夹下创建时间最早的文件
2012-03-16 · 知道合伙人软件行家
关注
展开全部
// 取得文件创建时间
function GetFileCreationTime(const FileName: String): TDateTime;
var
FileTime: TFileTime;
LocalFileTime: TFileTime;
hFile: THandle;
SystemTime: TSystemTime;
begin
Result := 0;
FileTime.dwLowDateTime := 0;
FileTime.dwHighDateTime := 0;
hFile := FileOpen(FileName, fmShareDenyNone);
try
if hFile <> 0 then
begin
Windows.GetFileTime(hFile, @FileTime, nil, nil);
FileTimeToLocalFileTime(FileTime, LocalFileTime);
FileTime := LocalFileTime;
end;
finally
FileClose(hFile);
end;
if FileTimeToSystemTime(FileTime, SystemTime) then
Result := SystemTimeToDateTime(SystemTime);
end;
function GetFileCreationTime(const FileName: String): TDateTime;
var
FileTime: TFileTime;
LocalFileTime: TFileTime;
hFile: THandle;
SystemTime: TSystemTime;
begin
Result := 0;
FileTime.dwLowDateTime := 0;
FileTime.dwHighDateTime := 0;
hFile := FileOpen(FileName, fmShareDenyNone);
try
if hFile <> 0 then
begin
Windows.GetFileTime(hFile, @FileTime, nil, nil);
FileTimeToLocalFileTime(FileTime, LocalFileTime);
FileTime := LocalFileTime;
end;
finally
FileClose(hFile);
end;
if FileTimeToSystemTime(FileTime, SystemTime) then
Result := SystemTimeToDateTime(SystemTime);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询