if not DirectoryExists(sour_path) then
begin
Result.Clear;
exit;
end;
TmpList := TStringList.Create;
TmpList.Clear;
if FindFirst(sour_path + '*.*', faAnyfile, FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) then
begin
if ((FileRec.Name <> '.') and (FileRec.Name <> '..')) then
FList(sour_path);
end;
until FindNext(FileRec) <> 0;
FindClose(FileRec);
if FindFirst(sour_path + sour_file, faAnyfile, subFileRec) = 0 then
repeat
if ((subFileRec.Attr and faDirectory) = 0) then
TmpList.Add(sour_path + subFileRec.Name);
until FindNext(subFileRec) <> 0;
FindClose(subFileRec);
for i := 0 to TmpList.Count - 1 do
Result.Add(TmpList.Strings[i]);
for i:=0 to Length(a)-1 do begin
Log(
a[i]+' '+
'GetCreationTime:' +DateTimeToStr(IOUtils.TFile.GetCreationTime (a[i]))+ ' ' +
'GetLastAccessTime:'+DateTimeToStr(IOUtils.TFile.GetLastAccessTime(a[i]))+ ' ' +
'GetLastWriteTime:' +DateTimeToStr(IOUtils.TFile.GetLastWriteTime (a[i]))+ ' ' +
' '
);
end;
end;
写成函数,返回值为TStrings,可带时间戳,可不带
function FList(ASourFile: string; TimeState: Boolean = False): TStrings;
var
a: TStringDynArray;
i: integer;
begin
result := TStringList.Create;
if TimeState = True then
begin
a := IOUtils.TDirectory.GetFiles(ASourFile,TSearchOption.soAllDirectories,nil); // 获取一个目录下所有文件名,包括子目录
for i := 0 to Length(a)-1 do
result.add(a[i] + ':' + DateTimeToStr(IOUtils.TFile.GetCreationTime(a[i]))); // 文件名 + 创建时间
end else
begin
a := IOUtils.TDirectory.GetFiles(ASourFile,TSearchOption.soAllDirectories,nil); // 获取一个目录下所有文件名,包括子目录
for i := 0 to Length(a)-1 do
result.add(a[i]); // 文件名 + 创建时间
end;
获取文件创建时间: 只到当天
procedure TForm2.SpeedButton4Click(Sender: TObject);
var
DateTime: TDateTime;
begin
FileAge('D:\AAA.txt', DateTime);
ShowMessage(DateTimeToStr(DateTime));
end;