function FindFileList(AFileList: TStrings; ARootDir: string; ARecursive: Boolean; AExt: string): Integer;
var
hFind: THandle;
wfd : TWin32FindData;
bContinue: Boolean;
begin
if ARootDir[Length(ARootDir)] <> '\\' then
ARootDir := ARootDir + '\\';
hFind := Windows.FindFirstFile(PChar(ARootDir + '*.*'), wfd);
bContinue := (hFind <> INVALID_HANDLE_VALUE);
while bContinue do
begin
if wfd.cFileName[0] <> '.' then
begin
if ARecursive and ((wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0) then
begin
FindFileList(AFileList, ARootDir + wfd.cFileName + '\\', ARecursive, AExt);
end
else
begin
if (AExt = '.*') or (ExtractFileExt(wfd.cFileName) = AExt) then
AFileList.Add(ARootDir + wfd.cFileName);
end;
end;
function FindFileList(AFileList: TStrings; ARootDir: string; ARecursive: Boolean; AExt: string): Integer;
var
hFind: THandle;
wfd : TWin32FindData;
bContinue: Boolean;
begin
if ARootDir[Length(ARootDir)] <> '\\' then
ARootDir := ARootDir + '\\';
hFind := Windows.FindFirstFile(PChar(ARootDir + '*.*'), wfd);
bContinue := (hFind <> INVALID_HANDLE_VALUE);
while bContinue do
begin
if wfd.cFileName[0] <> '.' then
begin
if ARecursive and ((wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0) then
begin
FindFileList(AFileList, ARootDir + wfd.cFileName + '\\', ARecursive, AExt);
end
else
begin
if (AExt = '.*') or (ExtractFileExt(wfd.cFileName) = AExt) then
AFileList.Add(ARootDir + wfd.cFileName);
end;
end;
bContinue := Windows.FindNextFile(hFind, wfd);
end;
Windows.FindClose(hFind);
Result := AFileList.Count;
end;
그럴리 없겠지만 혹시 Sorting되어있지 않은 리스트가 있을경우 함수 호출후 AFileList를 Sort시켜주세요.
TStringList.Sort등을 이용하시면 됩니다...
도움이 되셨길 바랍니다.