码迷,mamicode.com
首页 > 其他好文 > 详细

遍历指定目录下指定类型文件的函数(fatkun Fix版)

时间:2015-03-14 16:40:19      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:

// ================================================================
// 遍历某个文件夹及子文件夹下某种文件,
// 使用说明
// _GetFileList(ListBox1.Items, ‘c:\‘, ‘.doc‘);
// _GetFileList(MyTStringList, ‘c:\‘, ‘.exe‘);
// 这不是万一博客的原版咧,是1L的fatkun修复的一版,且不管看不看得懂,收藏个先

// ================================================================
procedure _GetFileList(AStrings: TStrings; ASourFile,FileName: string);
var sour_path,sour_file: string;
TmpList:TStringList;
FileRec, subFileRec:TSearchrec;
i: Integer;
begin
if copy(ASourFile,length(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 begin
if (Pos(sour_file,sour_path+FileRec.Name)>0) then
TmpList.Add(sour_path+FileRec.Name);
end;

until FindNext(FileRec)<>0;

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

TmpList.Free;
end;

遍历指定目录下指定类型文件的函数(fatkun Fix版)

标签:

原文地址:http://www.cnblogs.com/FanYs/p/4337721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!