核心提示:function GetFilenames(FilePath,ExtMask: String):TStrings; //遍历目录var FileRec :TSearchrec;begin if Dir...
function GetFilenames(FilePath,ExtMask: String):TStrings; //遍历目录var
FileRec :TSearchrec;
begin
if DirectoryExists(FilePath) then
begin
if FilePath[Length(FilePath)] <> '\' then FilePath := FilePath + '\';
Result := TStringList.Create;
if FindFirst(FilePath + ExtMask,faAnyfile,FileRec) = 0 then
repeat
if (FileRec.Attr and faDirectory) = 0 then
Result.Add(FilePath + FileRec.Name);
until FindNext(FileRec) <> 0;
FindClose(FileRec);
end;
end;
function GetFilenamesEx(FilePath,ExtMask :String):TStrings; //遍历目录及子目录
var
FileRec :TSearchrec;
begin
if DirectoryExists(FilePath) then
begin
if FilePath[Length(FilePath)] <> '\' then FilePath := FilePath + '\';
Result := TStringList.Create;
if FindFirst(FilePath + ExtMask,faAnyfile,FileRec) = 0 then
repeat
if (FileRec.Attr and faDirectory) <> 0 then
begin
if (FileRec.Name<> '.') and (FileRec.Name <> '..') then
Result.AddStrings(GetFilenames(FilePath + FileRec.Name + '\',ExtMask));
end
else Result.Add(FilePath + FileRec.Name);
until FindNext(FileRec) <> 0;
FindClose(FileRec);
end;
end;