Delphi如何实现自动查找文件夹下的下一级文件夹的txt文本文件路径并将路径导入listview内?
Delphi如何实现自动查找A文件夹下的下一级B、C、D文件夹下的txt文本文件路径并将路径导入listview内?...
Delphi如何实现自动查找A文件夹下的下一级B、C、D文件夹下的txt文本文件路径并将路径导入listview内?
展开
2个回答
展开全部
我这有一个一直在用的函数,FindFileName是文件夹路径,Filetpye 是文件类型,Tstr是一个TStrings,用来记录搜索出来的所有文件路径。你需要做的就是调用这个函数,并把Tstr导入到listview中
procedure FindFile(FindFileName:string; Filetpye : string ;Tstr:TStrings);
var
FSearchRec,
DSearchRec: TSearchRec;
FindResult: integer;
function IsDirNotation(ADirName: String): Boolean;
begin
Result := (ADirName = '.') or (ADirName = '..');
end;
begin
if FindFileName[Length(FindFileName)]<> '\' then
FindFileName:=FindFileName+'\';
FindResult := FindFirst(FindFileName+'*.*', faDirectory, DSearchRec);
//tstr.Add(FindFileName+fsearchrec.Name);
while FindResult = 0 do
begin
if ((DSearchRec.Attr and faDirectory) = faDirectory) and not
IsDirNotation(DSearchRec.Name) then
begin
FindFile(FindFileName+DSearchRec.Name,Filetpye,Tstr);
// tstr.Add(FindFileName+fsearchrec.Name);
end;
FindResult := FindNext(DSearchRec);
end;
FindResult := FindFirst(FindFileName+'*.*',faAnyFile+faHidden+
faSysFile,FSearchRec);
// tstr.Add(FindFileName+fsearchrec.Name);
try
while FindResult = 0 do
begin
//ShowMessage(FindFileName+fsearchrec.Name);
if Pos(Filetpye,FindFileName+fsearchrec.Name)>0 then
begin
tstr.Add(FindFileName+fsearchrec.Name);
end;
FindResult := FindNext(FSearchRec);
end;
finally
FindClose(FSearchRec);
end;
Findclose(DSearchRec);
end;
procedure FindFile(FindFileName:string; Filetpye : string ;Tstr:TStrings);
var
FSearchRec,
DSearchRec: TSearchRec;
FindResult: integer;
function IsDirNotation(ADirName: String): Boolean;
begin
Result := (ADirName = '.') or (ADirName = '..');
end;
begin
if FindFileName[Length(FindFileName)]<> '\' then
FindFileName:=FindFileName+'\';
FindResult := FindFirst(FindFileName+'*.*', faDirectory, DSearchRec);
//tstr.Add(FindFileName+fsearchrec.Name);
while FindResult = 0 do
begin
if ((DSearchRec.Attr and faDirectory) = faDirectory) and not
IsDirNotation(DSearchRec.Name) then
begin
FindFile(FindFileName+DSearchRec.Name,Filetpye,Tstr);
// tstr.Add(FindFileName+fsearchrec.Name);
end;
FindResult := FindNext(DSearchRec);
end;
FindResult := FindFirst(FindFileName+'*.*',faAnyFile+faHidden+
faSysFile,FSearchRec);
// tstr.Add(FindFileName+fsearchrec.Name);
try
while FindResult = 0 do
begin
//ShowMessage(FindFileName+fsearchrec.Name);
if Pos(Filetpye,FindFileName+fsearchrec.Name)>0 then
begin
tstr.Add(FindFileName+fsearchrec.Name);
end;
FindResult := FindNext(FSearchRec);
end;
finally
FindClose(FSearchRec);
end;
Findclose(DSearchRec);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询