반응형
// 지정한 폴더의 파일 리스트 가져오기 : 서브 폴더 검색 대응
function FindFiles(const sPath, sMask: string; slFiles: TStringList; bSubDir: boolean): integer;
var
iFindResult: integer;
srSchRec : TSearchRec;
begin
result := 0;
iFindResult := FindFirst(sPath + sMask, faAnyFile - faDirectory, srSchRec);
while iFindResult = 0 do
begin
slFiles.Add(sPath + srSchRec.Name);
iFindResult := FindNext(srSchRec);
end;
FindClose(srSchRec);
if bSubDir then
begin
iFindResult := FindFirst(sPath + '*.*', faDirectory, srSchRec);
while iFindResult = 0 do
begin
if (srSchRec.Name <> '.') and (srSchRec.Name <> '..') then
result := result + FindFiles(sPath + srSchRec.Name + '\', sMask, slFiles, TRUE);
iFindResult := FindNext(srSchRec);
end;
FindClose(srSchRec);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sl: TStringList;
begin
Button1.Enabled := false;
sl := TStringList.Create;
sl.Clear;
FindFiles('D:\Data\', '*.doc', sl, True);
Listbox1.Items := sl;
sl.Free;
Button1.Enabled := True;
end;
출처 : http://wwwi.tistory.com/294
반응형