function TfrmMain.GetPathFile(S:String;Attr:Integer):TStringList;
var
sr:TSearchRec;
fReturn:Integer;
FileList:TStringList;
begin
FileList:=TStringList.Create;
fReturn:=FindFirst(S,Attr,sr);
if fReturn=0 then
begin
repeat
begin
if (Attr=faAnyFile) and (length(sr.Name)<=11) then
FileList.Add(sr.Name)
else if (Attr=faDirectory) and (length(sr.Name)>2) then
begin
try
FileList.Add(ConvertToSort(sr.Name));
except
end;
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
Result:=FileList;
end;
调用方法:
GetPathFile('C:/windows/*.txt';faAnyFile):返回的TStringList就包含了所有的txt文件。
这是我的一个函数,有些对你来说没用的东西,可以删掉。