procedure LoadDirFiles(Dir: string; Files: TStrings; bRecursive: Boolean); procedure DoLoad(Dir: string; Files: TStrings); var F: TSearchRec; hFind: Integer; begin if (Dir <> '') and (Dir[Length(Dir)] <> '\') then Dir := Dir + '\'; hFind := FindFirst(Dir + '*.*', faAnyFile, F); while hFind = 0 do begin if (F.Name <> '.') and (F.Name <> '..') then begin if F.Attr and faDirectory <> faDirectory then Files.Add(Dir + F.Name) else if bRecursive then begin DoLoad(Dir + F.Name, Files); Files.AddObject(Dir + F.Name, TObject(1)); end; end; hFind := FindNext(F); end; FindClose(F); end;begin Files.BeginUpdate; try Files.Clear; DoLoad(Dir, Files); finally Files.EndUpdate; end; end; eg: LoadDirFiles('放dbf文件夹路径', ListBox.Items, False);
var
F: TSearchRec;
hFind: Integer;
begin
if (Dir <> '') and (Dir[Length(Dir)] <> '\') then
Dir := Dir + '\';
hFind := FindFirst(Dir + '*.*', faAnyFile, F);
while hFind = 0 do
begin
if (F.Name <> '.') and (F.Name <> '..') then
begin
if F.Attr and faDirectory <> faDirectory then
Files.Add(Dir + F.Name)
else if bRecursive then
begin
DoLoad(Dir + F.Name, Files);
Files.AddObject(Dir + F.Name, TObject(1));
end;
end;
hFind := FindNext(F);
end;
FindClose(F);
end;begin
Files.BeginUpdate;
try
Files.Clear;
DoLoad(Dir, Files);
finally
Files.EndUpdate;
end;
end;
eg:
LoadDirFiles('放dbf文件夹路径', ListBox.Items, False);
hFind := FindFirst(Dir + '*.dbf', faAnyFile, F);