Delphi如何实现自动查找文件夹下的下一级文件夹的txt文本文件路径并将路径导入listview内?

2024-12-18 07:36:25
推荐回答(2个)
回答1:

我这有一个一直在用的函数,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;

回答2:

我做过这个效果,不过发不出来,你hi我,我发你。