遍历指定目录下指定类型文件的函数
// ================================================================
// 遍历某个文件夹下某种文件,
// 使用说明
//  _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;

// ================================================================
// 遍历某个文件夹及子文件夹下某种文件,
// 使用说明
//  _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;

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

TmpList.Free;
end;

delphi遍历指定目录下指定类型文件的函数的更多相关文章

  1. 微软BI 之SSIS 系列 - 在 SSIS 中将指定目录下的所有文件分类输出到不同文件夹

    开篇介绍 比如有这样的一个需求,旧的一个业务系统通常将产出的文件输出到同一个指定的目录下的不同子目录,输出的文件类型有 XML,EXCEL, TXT 这些不同后缀的文件.现在需要在 SSIS 中将它们 ...

  2. Python —— 批量替换指定目录下的所有文件中指定字符串

    参考:http://blog.csdn.net/zcwfengbingdongguke/article/details/13951527 代码: #!/usr/bin/python import os ...

  3. [No000073]C#直接删除指定目录下的所有文件及文件夹(保留目录)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. linux复制指定目录下的全部文件到另一个目录中

    linux复制指定目录下的全部文件到另一个目录中复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir ...

  5. Java基础知识强化之IO流笔记49:IO流练习之 复制指定目录下指定后缀名的文件并修改名称的案例

    1. 复制指定目录下指定后缀名的文件并修改名称的案例     需求:复制指定目录下的指定文件,并修改后缀名.  • 指定的文件是:.java文件.     • 指定的后缀名是:.jad     • 指 ...

  6. c# 获取指定目录下的所有文件并显示在网页上

    参考文献: FileInfo 的使用  https://msdn.microsoft.com/zh-cn/library/system.io.fileinfo_methods(v=vs.110).as ...

  7. linux复制指定目录下的全部文件到另一个目录中,linux cp 文件夹

    linux复制指定目录下的全部文件到另一个目录中复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir ...

  8. C++:获取指定目录下的所有文件

    1.获得指定目录下的所有文件(不搜索子文件夹) 需要包含的头文件 #include <io.h> #include <string> #include <vector&g ...

  9. C#直接删除指定目录下的所有文件及文件夹(保留目录)

    #region 直接删除指定目录下的所有文件及文件夹(保留目录) /// <summary> /// 直接删除指定目录下的所有文件及文件夹(保留目录) /// </summary&g ...

随机推荐

  1. Key Set

    http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=594 Key Set Time Limit: 2000 ...

  2. BUUCTF | MD5

    题目:e00cf25ad42683b3df678c61f42c6bda flag{admin1} 算是一个资源收集吧,Orz,https://www.cmd5.com/

  3. 【已转移】【Java架构:基础技术】一篇文章搞掂:SVN

    一个例子: 公司的SVN代码中,含有target等文件夹,每次生成运行后,有很多文件打扰签入 处理方案: 1.CheckOut时,点击ChooseItems选项,不要选择这些target文件夹(有点麻 ...

  4. python练习题之全选框全不选反选

    功能 实现分为两大部分: 第一body 部分,1,通过<li>无序列表标签实现选项的基本样式,通过input的checkbox标签实现里面的复选框功能.用到了标签的嵌套.然后选项的js方法 ...

  5. 2019-2020-1 20175223 《信息安全系统设计基础》MyOD

    目录 一.要求 二.设计流程 1. 需求分析 2. 概要设计 伪代码 3. 详细设计 main.c tans_0x.c tans_pr.c tansp.h 三.编写Makefile,并制作动.静态库 ...

  6. T-SQL 创建触发器 禁止插入空值

    ---假设在SQL SERVER 2005里面有一张表,其中有两个字段需要做唯一性约束, ---不能有重复值,但是允许其为空值,如果都是空值,则允许重复 CREATE TRIGGER [dbo].[i ...

  7. English-Words with 'ir'

    hire thirty thirteen third sir birthday shirt stir circle dirty skirt affirm affirmation affirmable ...

  8. Frida Android hook native层__system_property_get的最终方案

    记录这个问题的起因是,在hook时遇到了修改内容长度,超过原长度时,会出现显示不全的问题. 比如把nexus 5改成nexus 100,只会显示nexus 1. 所以去读了下源码 int __syst ...

  9. 为什么学python

    一.什么是Python Python [1](英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/), 是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum发明. ...

  10. FZU 2059 MM

    Description There is a array contain N(1<N<=100000) numbers. Now give you M(1<M<10000) q ...