遍历所有子目录,找出全部文件,将文件完整路径写入到一个TStringList中去。
function TraversalFolder(FileList: TStrings; Folder: string): Boolean;
var
hFindFile: THandle;
FindFileData: _WIN32_FIND_DATAW;
FileName: string;
begin
Result := False;
if Folder = '' then
Exit;
if Folder[Length(Folder)] <> '\' then
Folder := Folder + '\';
hFindFile := FindFirstFile(PChar(Folder + '*.*'), FindFileData);
if hFindFile = INVALID_HANDLE_VALUE then
Exit;
try
repeat
FileName := FindFileData.cFileName;
if (FileName = '.') or (FileName = '..') then
Continue;
if (FindFileData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = FILE_ATTRIBUTE_DIRECTORY) then
begin
TraversalFolder(FileList, Folder + FileName + '\');
Continue;
end;
if not (FindFileData.dwFileAttributes and FILE_ATTRIBUTE_ARCHIVE = FILE_ATTRIBUTE_ARCHIVE) then
continue;
FileList.Add(Folder + FileName);
until not FindNextFile(hFindFile, FindFileData);
Result := True;
finally
Windows.FindClose(hFindFile);
end;
end;