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;
// ================================================================
// 遍历某个文件夹及子文件夹下某种文件,
// 使用说明
// _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遍历指定目录下指定类型文件的函数的更多相关文章
- 微软BI 之SSIS 系列 - 在 SSIS 中将指定目录下的所有文件分类输出到不同文件夹
开篇介绍 比如有这样的一个需求,旧的一个业务系统通常将产出的文件输出到同一个指定的目录下的不同子目录,输出的文件类型有 XML,EXCEL, TXT 这些不同后缀的文件.现在需要在 SSIS 中将它们 ...
- Python —— 批量替换指定目录下的所有文件中指定字符串
参考:http://blog.csdn.net/zcwfengbingdongguke/article/details/13951527 代码: #!/usr/bin/python import os ...
- [No000073]C#直接删除指定目录下的所有文件及文件夹(保留目录)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- linux复制指定目录下的全部文件到另一个目录中
linux复制指定目录下的全部文件到另一个目录中复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir ...
- Java基础知识强化之IO流笔记49:IO流练习之 复制指定目录下指定后缀名的文件并修改名称的案例
1. 复制指定目录下指定后缀名的文件并修改名称的案例 需求:复制指定目录下的指定文件,并修改后缀名. • 指定的文件是:.java文件. • 指定的后缀名是:.jad • 指 ...
- c# 获取指定目录下的所有文件并显示在网页上
参考文献: FileInfo 的使用 https://msdn.microsoft.com/zh-cn/library/system.io.fileinfo_methods(v=vs.110).as ...
- linux复制指定目录下的全部文件到另一个目录中,linux cp 文件夹
linux复制指定目录下的全部文件到另一个目录中复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir ...
- C++:获取指定目录下的所有文件
1.获得指定目录下的所有文件(不搜索子文件夹) 需要包含的头文件 #include <io.h> #include <string> #include <vector&g ...
- C#直接删除指定目录下的所有文件及文件夹(保留目录)
#region 直接删除指定目录下的所有文件及文件夹(保留目录) /// <summary> /// 直接删除指定目录下的所有文件及文件夹(保留目录) /// </summary&g ...
随机推荐
- PHP curl_multi_add_handle函数
curl_multi_add_handle — 向curl批处理会话中添加单独的curl句柄 说明 int curl_multi_add_handle ( resource $mh , resourc ...
- vue和php-前后台交互
vue和php-前后台交互 前端主要代码: <template> <div class="main-member-info"> <form @subm ...
- 使用mysql应该注意的细节
一.表及字段的命名规范 1.可读性原则 使用大写和小写来格式化的库对象名字以获得良好的可读性. 例如:使用CustAdress而不是custaddress来提高可读性.(这里注意有些DBMS系统对表名 ...
- jq与js获取值操作
jq与js获取值操作 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...
- Python中的浮点数原理与运算分析
Python中的浮点数原理与运算分析 本文实例讲述了Python中的浮点数原理与运算.分享给大家供大家参考,具体如下: 先看一个违反直觉的例子: >>> s = 0. > ...
- python学习笔记:try与except处理异常语句
写代码的时候会遇到各种各样的异常,那么代码就不会继续往下走了.比如说10除以0是错误的,因为除数不能为零学会捕捉异常,在异常出现的时候我们要做什么操作. 本文中只做简单使用的讲解,详细使用方法可以参考 ...
- 最小,独立,可分发的跨平台Web服务器
最近,我一直在编写大量较小的wsgi应用程序,并希望找到一个可以分布式,预先配置为运行特定应用程序的Web服务器.我知道有些东西可以用于wsgi应用程序,例如twisted和cherrypy,但它们似 ...
- Java-技术专区-异步编程指南
通过本文你可以了解到下面这些知识点: Future 模式介绍以及核心思想 核心线程数.最大线程数的区别,队列容量代表什么: ThreadPoolTaskExecutor 饱和策略: SpringBoo ...
- 封装一个Js 对象 生成Json
<script src="~/Content/Scripts/jquery-1.11.3.min.js"></script> <script> ...
- 定时任务crond介绍
定时任务cornd crond介绍: crond是linux系统中用来定期(或周期性)执行命令或指定程序任务脚本的一种程序. 查看crontab帮助: [root@db01 ~]# crontab - ...