首页 > 其他 > 详细

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

时间:2015-03-14 16:39:51      阅读:371      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!