//刚好正在开发的程序有一个类似的函数,自己改造一下吧。用了递归。 //定义一个外部变量,slTemp(TStringList)用来保存找到的文件信息。procedure FindAllFile(FPath:String); var sr: TSearchRec; FileAttrs: Integer; begin FileAttrs := faReadOnly + faHidden+ faSysFile+ faVolumeID+ faDirectory+faArchive+faAnyFile; if FindFirst(FPath+'*.txt', FileAttrs, sr) = 0 then begin repeat //是目录 if ((sr.Attr and faDirectory) = faDirectory) and (sr.Name<>'.') and (sr.Name<>'..') then begin FindAllFile(FPath+sr.Name+'\'); end else begin //是文件 slTemp.Add(FPath+sr.Name); end; until FindNext(sr) <> 0; FindClose(sr); end; end;
procedure FindAllFile(FPath:String); var sr: TSearchRec; FileAttrs: Integer; begin FileAttrs := faReadOnly + faHidden+ faSysFile+ faVolumeID+ faDirectory+faArchive+faAnyFile; if FindFirst(FPath+'*.txt', FileAttrs, sr) = 0 then begin repeat //是目录 if ((sr.Attr and faDirectory) = faDirectory) and (sr.Name<>'.') and (sr.Name<>'..') then begin FindAllFile(FPath+sr.Name+'\'); end else begin //是文件 slTemp.Add(FPath+sr.Name); end; until FindNext(sr) <> 0; FindClose(sr); end; end; 是可以实现的,学习... 我平时也借助一些第三方的控件来实现,比如:Disk.Controls 这个来找文件是很方便的,绑定几个属性(查找选项)就OK 了
//定义一个外部变量,slTemp(TStringList)用来保存找到的文件信息。procedure FindAllFile(FPath:String);
var sr: TSearchRec;
FileAttrs: Integer;
begin
FileAttrs := faReadOnly + faHidden+ faSysFile+ faVolumeID+ faDirectory+faArchive+faAnyFile;
if FindFirst(FPath+'*.txt', FileAttrs, sr) = 0 then begin
repeat
//是目录
if ((sr.Attr and faDirectory) = faDirectory)
and (sr.Name<>'.') and (sr.Name<>'..') then begin
FindAllFile(FPath+sr.Name+'\');
end else begin
//是文件
slTemp.Add(FPath+sr.Name);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
var sr: TSearchRec;
FileAttrs: Integer;
begin
FileAttrs := faReadOnly + faHidden+ faSysFile+ faVolumeID+ faDirectory+faArchive+faAnyFile;
if FindFirst(FPath+'*.txt', FileAttrs, sr) = 0 then begin
repeat
//是目录
if ((sr.Attr and faDirectory) = faDirectory)
and (sr.Name<>'.') and (sr.Name<>'..') then begin
FindAllFile(FPath+sr.Name+'\');
end else begin
//是文件
slTemp.Add(FPath+sr.Name);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
是可以实现的,学习...
我平时也借助一些第三方的控件来实现,比如:Disk.Controls
这个来找文件是很方便的,绑定几个属性(查找选项)就OK 了
来晚了,已经解决