Delphi中搜索文件获取文件名的同时获取文件大小和创建时间怎么弄啊 这是获取文件名 文件路径的代码~~~~怎么写获取文件大小 和创建日期的代码
procedure TForm5.GetDirsAndFiles(APath: String; AList: TStrings; BList: TStrings;
HasPath: Boolean);
var
F: TSearchRec;
FileName, RFileName: String;
begin
if FindFirst(APath + '\*.*', faAnyFile, F) = 0 then
repeat
FileName := F.Name;
if (FileName <> '.') and (FileName <> '..') then begin
if HasPath then
RFileName := APath + '\' + FileName
else
RFileName := FileName;
if UpperCase(ExtractFileExt(RFileName)) = '.PDF' then
begin
AList.Add(FileName);
Blist.Add(APath);
end;
Caption := '搜索-' + RFileName;
if F.Attr and faDirectory <> 0 then
GetDirsAndFiles(APath + '\' + F.Name, AList,Blist,True);
end;
Application.ProcessMessages;
until FindNext(F) <> 0;
FindClose(F);
end;
procedure TForm5.GetDirsAndFiles(APath: String; AList: TStrings; BList: TStrings;
HasPath: Boolean);
var
F: TSearchRec;
FileName, RFileName: String;
begin
if FindFirst(APath + '\*.*', faAnyFile, F) = 0 then
repeat
FileName := F.Name;
if (FileName <> '.') and (FileName <> '..') then begin
if HasPath then
RFileName := APath + '\' + FileName
else
RFileName := FileName;
if UpperCase(ExtractFileExt(RFileName)) = '.PDF' then
begin
AList.Add(FileName);
Blist.Add(APath);
end;
Caption := '搜索-' + RFileName;
if F.Attr and faDirectory <> 0 then
GetDirsAndFiles(APath + '\' + F.Name, AList,Blist,True);
end;
Application.ProcessMessages;
until FindNext(F) <> 0;
FindClose(F);
end;
解决方案 »
- Delphi 怎樣作一個文件夾加密程序
- 请问大家谁知道怎么把一个DBGRID显示的远程数据库的内容生成为本地的一个表
- sql的一个问题,在线等!!!(高分啊)
- 请问哪里可以下载到Delphi6。0。谢谢了!
- 我執行select * from employee這個句子沒有問題,可以打開employee 這個表.可是改成這樣就有問題了.select employee_id,employee_name fro
- Delphi里如何将QRChart绘制的图片保存到硬盘
- 用TDrawGriD网格绘图出问题,在线等待!!
- webconnection之客户异常断开时,server端的释放
- 求简单一点的 delphi5+oracle8 以上的程序,给分100, up者有分,不够在加,谢了
- 那里有tts(text to speech)控件下载?
- 求AVI播放窗口拉伸、对位等参数
- RADStudioXE 你是我的倚天剑!
procedure TForm1.Button1Click(Sender: TObject);
var
f: file of Byte;
size: Longint;
sr: TSearchRec;
dft: DWORD;
begin
if OpenDialog1.Execute then
begin
AssignFile(f, OpenDialog1.FileName);
Reset(f);
try
size := FileSize(f);
showmessage('File size in bytes: ' + IntToStr(size));
FindFirst(OpenDialog1.FileName, faAnyFile, sr);
FileTimeToDosDateTime(sr.FindData.ftCreationTime,
LongRec(dft).Hi, LongRec(dft).Lo);
showmessage(DateTimeToStr(FileDateToDateTime(dft)));
finally
CloseFile(f);
end;
end;
end;
{ 转换文件的时间格式 }
var
Tct:_SystemTime;
Temp:_FileTime;
begin
FileTimeToLocalFileTime(Fd,Temp);
FileTimeToSystemTime(Temp,Tct);
CovFileDate:=SystemTimeToDateTime(Tct);
end;procedure TForm1.Button2Click(Sender: TObject);
const
Model='yyyy/mm/dd'; { 设定时间格式 }
var
Tp:TSearchRec; { 申明Tp为一个查找记录 }
T1,T2,T3:string;
begin
FindFirst('D:\SQL10.TXT',faAnyFile,Tp); { 查找目标文件 }
T1:=FormatDateTime(Model,CovFileDate(Tp.FindData.ftCreationTime));
{ 返回文件的创建时间 }
T2:=FormatDateTime(Model,CovFileDate(Tp.FindData.ftLastWriteTime));
{ 返回文件的修改时间 }
T3:=FormatDateTime(Model,Now);
{ 返回文件的当前访问时间 }
FindClose(Tp);
end;
begin
if OpenDialog1.Execute then
begin
ShowMessage(IntToStr(FileSizeByName(OpenDialog1.Filename)));
end;