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开发WINCE应用程序
- 请求把下面VC程序翻译成delphi语言。
- 求教???????
- ClientDataset每次查询出的数据都为前几天的数,明明表里有录数,但是不能更新,用socket连的三层。
- 如何实现在ComboBox中回车的时候打开下拉菜单进行选择?
- WIN的画图程序中,怎么做虚拟画直线这块呢?分不够可以加
- INDY 得 IDftp 和 fastnet 的 NMftp 谁好些啊?
- 用Ado 连接 mysql, Clientdataset.applyupdate(-1) 时 的事务处理出错
- 奉一套类似于oicq的源代码,(用delphi6.0编写的)(不过要决以下问题)
- 數據改變精度!為什麼????
- 求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;