給個範例函式讓你參考
function CheckSearch(ReturnCode: DWORD): boolean;
var
Error: EWin32Error;
begin
Case ReturnCode of
ERROR_SUCCESS: Result := True;
ERROR_FILE_NOT_FOUND, ERROR_NO_MORE_FILES, ERROR_PATH_NOT_FOUND: Result := False;
else begin
Error := EWin32Error.CreateResFmt(@SWin32Error, [ReturnCode,
SysErrorMessage(ReturnCode)]);
Error.ErrorCode := ReturnCode;
raise Error;
end;
end;
end;
procedure SearchFiles(const SourcePath: string; SearchList: TStrings);
procedure SearchFile(Path: string);
var
FindFile: TSearchRec;
begin
Path := IncludeTrailingBackslash(Path);
if CheckSearch(FindFirst(Path + '*.*', faAnyFile, FindFile)) then
repeat
if ((FindFile.Attr and faDirectory) = faDirectory) then begin
if (FindFile.Name[1] <> '.') then SearchFile(Path + FindFile.Name);
end else
SearchList.Add(Path+FindFile.Name);
until not CheckSearch(FindNext(FindFile));
end;
begin
SearchFile(SourcePath);
end;