Delphi下遍历文件夹下所有文件的递归算法
2013-10-29 21:03
134 查看
{-------------------------------------------------------------------------------
过程名: MakeFileList 遍历文件夹及子文件夹
参数: Path,FileExt:string 1.需要遍历的目录 2.要遍历的文件扩展名
返回值: TStringList
USE StrUtils
Eg:ListBox1.Items:= MakeFileList( 'E:\极品飞车','.exe') ;
ListBox1.Items:= MakeFileList( 'E:\极品飞车','.*') ;
-------------------------------------------------------------------------------}
function MakeFileList(Path,FileExt:string):TStringList ;
var
sch:TSearchrec;
begin
Result:=TStringlist.Create;
if rightStr(trim(Path), 1) <> '\' then
Path := trim(Path) + '\'
else
Path := trim(Path);
if not DirectoryExists(Path) then
begin
Result.Clear;
exit;
end;
if FindFirst(Path + '*', faAnyfile, sch) = 0 then
begin
repeat
Application.ProcessMessages;
if ((sch.Name = '.') or (sch.Name = '..')) then Continue;
if DirectoryExists(Path+sch.Name) then
begin
Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));
end
else
begin
if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then
Result.Add(Path+sch.Name);
end;
until FindNext(sch) <> 0;
SysUtils.FindClose(sch);
end;
end;
过程名: MakeFileList 遍历文件夹及子文件夹
参数: Path,FileExt:string 1.需要遍历的目录 2.要遍历的文件扩展名
返回值: TStringList
USE StrUtils
Eg:ListBox1.Items:= MakeFileList( 'E:\极品飞车','.exe') ;
ListBox1.Items:= MakeFileList( 'E:\极品飞车','.*') ;
-------------------------------------------------------------------------------}
function MakeFileList(Path,FileExt:string):TStringList ;
var
sch:TSearchrec;
begin
Result:=TStringlist.Create;
if rightStr(trim(Path), 1) <> '\' then
Path := trim(Path) + '\'
else
Path := trim(Path);
if not DirectoryExists(Path) then
begin
Result.Clear;
exit;
end;
if FindFirst(Path + '*', faAnyfile, sch) = 0 then
begin
repeat
Application.ProcessMessages;
if ((sch.Name = '.') or (sch.Name = '..')) then Continue;
if DirectoryExists(Path+sch.Name) then
begin
Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));
end
else
begin
if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then
Result.Add(Path+sch.Name);
end;
until FindNext(sch) <> 0;
SysUtils.FindClose(sch);
end;
end;
相关文章推荐
- Delphi下遍历文件夹下所有文件的递归算法
- Delphi下遍历文件夹下所有文件的递归算法
- Delphi下遍历文件夹下所有文件的递归算法
- 利用递归算法遍历所有文件并打印文件绝对路径(包括文件夹)
- Delphi 文件夹遍历所有文件包括子文件文件,并可通过后缀过滤
- Delphi 计算指定目录下所有文件的大小(遍历文件夹所有文件及目录)
- 递归算法遍历文件夹中所有文件&&递归删除文件夹
- 写一个函数,能够遍历一个文件夹下的所有文件和子文件夹
- C# 遍历目录下所有文件夹下的文件
- linux 下遍历文件夹下的所有文件
- androir 遍历所有文件夹,查询视频文件
- php遍历所有文件及文件夹的方法
- c#遍历一个文件夹下的所有文件包括子文件夹【原】
- java 如何递归遍历一个文件夹下的所有文件
- delphi 遍历所有文件夹
- JSP 遍历读取文件夹下所有文件,目录
- JAVA遍历一个文件夹中的所有文件
- 遍历文件夹及子文件夹所有文件
- c#遍历一个文件夹下的所有文件包括子文件夹
- python遍历文件夹中的所有jpg文件