文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Delphi两个遍历指定目录下指定类型文件的函数

Delphi两个遍历指定目录下指定类型文件的函数

时间:2010-11-05  来源:sunjun0427

sour_path:

=ExtractFilePath(ASourFile);
sour_file:=ExtractFileName(ASourFile);

 

 

if not DirectoryExists(sour_path) then
begin
AStrings.Clear;
exit;
end;

 

TmpList:

=TStringList.Create;
TmpList.Clear;

 

 

if FindFirst(sour_path+sour_file,faAnyfile,FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) = 0) then
begin
TmpList.Add(sour_path+FileRec.Name)
end;
until FindNext(FileRec)<>0;

 

SysUtils.FindClose(FileRec);

AStrings.Assign(TmpList);

TmpList.Free;

end;

 

 

// ================================================================
// 遍历某个文件夹及子文件夹下某种文件,
// 使用说明
//  _GetFileList(ListBox1.Items, 'c:\', '*.doc');
// _GetFileList(MyTStringList, 'c:\', '*.exe');
// ================================================================
procedure _GetFileList(AStrings: TStrings; ASourFile,
FileName: string);
var sour_path,sour_file: string;
TmpList:TStringList;
FileRec, subFileRec:TSearchrec;
i: Integer;
begin
if rightStr(trim(ASourFile), 1) <> '\' then
sour_path :=trim(ASourFile) + '\'
else
sour_path :=trim(ASourFile);
sour_file:= FileName;

 

 

if not DirectoryExists(sour_path) then
begin
AStrings.Clear;
exit;
end;

 

TmpList:

=TStringList.Create;
TmpList.Clear;

 

 

if FindFirst(sour_path+'*.*',faAnyfile,FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) then
begin
if ((FileRec.Name<> '.') and (FileRec.Name <> '..')) then
_GetFileList(AStrings, sour_path+ FileRec.Name + '\', sour_file);
end
else
if FindFirst(sour_path + FileName,faAnyfile,subFileRec) = 0 then
repeat
if ((subFileRec.Attr and faDirectory) = 0) then
TmpList.Add(sour_path+subFileRec.Name);
until FindNext(subFileRec)<>0;

 

 

until FindNext(FileRec)<>0;

 

SysUtils.FindClose(FileRec);

for i := 0 to TmpList.Count -1 do
AStrings.Add(TmpList.Strings[i]);

 

TmpList.Free;

end;
相关阅读 更多 +
排行榜 更多 +
我是班长去广告版下载

我是班长去广告版下载

模拟经营 下载
什么鸭小游戏安卓版下载

什么鸭小游戏安卓版下载

策略塔防 下载
极光影院官方最新版本2025下载

极光影院官方最新版本2025下载

趣味娱乐 下载