鱼C论坛

 找回密码
 立即注册

遍历指定目录下指定类型文件的函数(转载)

热度 1已有 468 次阅读2012-11-18 23:32 |个人分类:好文章| delphi

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

// ================================================================

// 遍历某个文件夹下某种文件,

// 使用说明

//       _GetFileList(ListBox1.Items,'c:\*.doc');

//           _GetFileList(MyTStringList,'c:\*.exe');

// ================================================================

procedure TForm1._GetFileList(AStrings: TStrings ; ASourFile: string);

var sour_path,sour_file: string;

    TmpList:TStringList;

    FileRec:TSearchrec;

begin

   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;


路过

鸡蛋
1

鲜花

握手

雷人

刚表态过的朋友 (1 人)

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 16:07

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部