FindFirst,FindNext,FindClose....
搜索个例子给你:
//遍历文件夹下的文件
procedure SearchFileEx(const Dir, Ext: string; Files: TStrings);
var
Found: TSearchRec;
i: integer;
Dirs: TStrings;
Finished: integer;
StopSearch: Boolean;
begin
StopSearch := False;
Dirs := TStringList.Create;
Finished := FindFirst(Dir + '*.*', 63, Found);
while (Finished = 0) and not (StopSearch) do
begin
if (Found.Name <> '.') then
begin
if (Found.Attr and faDirectory) = faDirectory then
Dirs.Add(Dir + Found.Name)
else
if Pos(UpperCase(Ext), UpperCase(Found.Name)) > 0 then
Files.Add(Dir + Found.Name);
end;
Finished := FindNext(Found);
end;
FindClose(Found);
if not StopSearch then
for i := 0 to Dirs.Count - 1 do
SearchFileEx(Dirs[i], Ext, Files);
Dirs.Free;
end;
//遍历文件夹下的文件,包括子文件夹
procedure FindSubDir(DirName: string; FileString: TStrings);
var
searchRec: TsearchRec;
begin
//找出所有下级子目录。
if (FindFirst(DirName + '*.*', faDirectory, SearchRec) = 0) then
begin
if IsValidDir(SearchRec) then
FileString.Add(DirName + SearchRec.Name);
while (FindNext(SearchRec) = 0) do
begin
if IsValidDir(SearchRec) then
FileString.Add(DirName + SearchRec.Name);
end;
end;
FindClose(SearchRec);
end;
function IsValidDir(SearchRec: TSearchRec): Boolean;
begin
if (SearchRec.Attr = 16) and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
Result := True
else
Result := False;
end;
请发表评论