SysUtils单元下的TSearchRec是一个记录类型,主要通过FindFirst, FindNext, and FindClose使用。

接上一篇举例说明TSearchRec常用成员

//sysGetFileList(List,'c:\','*.doc,*.exe');  List通过查找添加多文件
//sysGetFileList(List,'c:\','*.doc'); List通过查找添加单文件
procedure sysGetFileList(List: TStrings; SourFile,FileName: string);
var
S_Path: String;
TmpList,S_FileList: TStringList;
FileRec,SubFileRec: TSearchRec;
I: Integer;
IsFound: Boolean;
SysTime: TSystemTime;
FileTime: TFileTime;
begin
S_Path := IncludeTrailingPathDelimiter(Trim(SourFile)); //单元SysUtils中判断末尾是否包含文件夹路径符号'\',没有的则补全
if not DirectoryExists(S_Path) then
begin
List.Clear;
Exit;
end; S_FileList := TStringList.Create;
try
S_FileList.CommaText := FileName; TmpList := TStringList.Create;
for I := to S_FileList.Count - do
begin
if FindFirst(S_Path + S_FileList[I],faAnyFile,FileRec) = then
repeat
if ((FileRec.Attr and faDirectory) <> ) then
begin
if ((FileRec.Name <> '.') and (FileRec.Name <> '..')) then
sysGetFileList(TmpList,IncludeTrailingPathDelimiter(S_Path + FileRec.Name),FileName);
end
else
begin
if ((FileRec.Attr and faDirectory) = ) then
begin
TmpList.Add(S_Path + FileRec.Name);
TmpList.Add('FileRec.Size:' + IntToStr(FileRec.Size)); //文件大小
TmpList.Add('FileRec.Name:' + FileRec.Name); //文件名
TmpList.Add('FileRec.Attr:' + IntToStr(FileRec.Attr)); //文件属性
TmpList.Add('FileRec.ExcludeAttr:' + IntToStr(FileRec.ExcludeAttr)); //未知
TmpList.Add('FileRec.FindHandle:' + IntToStr(FileRec.FindHandle)); //文件句柄
FileTimeToLocalFileTime(FileRec.FindData.ftCreationTime,FileTime); //文件创建时间
FileTimeToSystemTime(FileTime,SysTime);
TmpList.Add('FileRec.FindData.ftCreationTime:' + DateTimeToStr(SystemTimeToDateTime(SysTime)));
FileTimeToLocalFileTime(FileRec.FindData.ftLastAccessTime,FileTime); //文件最后 ?? 时间
FileTimeToSystemTime(FileTime,SysTime);
TmpList.Add('FileRec.FindData.ftLastAccessTime:' + DateTimeToStr(SystemTimeToDateTime(SysTime)));
FileTimeToLocalFileTime(FileRec.FindData.ftLastWriteTime,FileTime); //文件最后修改时间
FileTimeToSystemTime(FileTime,SysTime);
TmpList.Add('FileRec.FindData.ftLastWriteTime:' + DateTimeToStr(SystemTimeToDateTime(SysTime)));
TmpList.Add('FileRec.FindData.nFileSizeHigh:' + FloatToStr(FileRec.FindData.nFileSizeHigh)); //文件大小Hight值
TmpList.Add('FileRec.FindData.nFileSizeLow:' + FloatToStr(FileRec.FindData.nFileSizeLow)); TmpList.Add('FileRec.TimeStamp:' + DateTimeToStr(FileRec.TimeStamp)); //实际值=文件最后修改时间<pre name="code" class="delphi">
end;
end;
until FindNext(FileRec) <> ;
end;
FindClose(FileRec.FindHandle); if TmpList.CommaText <> '' then //空文件夹不添加路径
begin
if List.CommaText <> '' then
List.CommaText := List.CommaText + List.Delimiter + TmpList.CommaText
else
List.CommaText := TmpList.CommaText;
end;
finally
FreeAndNil(TmpList);
FreeAndNil(S_FileList);
end;

测试文件:aa.docx;

返回结果

E:\***\Out\aa.docx
FileRec.Size:11619
FileRec.Name:aa.docx
FileRec.Attr:32
FileRec.ExcludeAttr:0
FileRec.FindHandle:31054560
FileRec.FindData.ftCreationTime:2015-02-07 10:37:00
FileRec.FindData.ftLastAccessTime:2015-02-07 11:16:15
FileRec.FindData.ftLastWriteTime:2015-02-07 11:16:15
FileRec.FindData.nFileSizeHigh:0
FileRec.FindData.nFileSizeLow:11619
FileRec.TimeStamp:2015-02-07 11:16:15

文件查找记录类型 - TSearchRec - 文件操作(二)的更多相关文章

  1. TypeScript 学习四 面向对象的特性,泛型,接口,模块,类型定义文件*.d.ts

    1,面向对象的特性一:类,继承,见上一篇博客: 2,面向对象的特性二: 泛型(generic):参数化的类型,一般用来限制集合的内容:指定只能放某个类型的元素 如下图中的尖括号中的Person,就代表 ...

  2. Linux C 读取文件夹下所有文件(包括子文件夹)的文件名【转】

    转自:https://www.cnblogs.com/xudong-bupt/p/3504442.html 本文:http://www.cnblogs.com/xudong-bupt/p/350444 ...

  3. 基于VC的声音文件操作(二)

    (二)VC的声音操作 操作声音文件,也就是将WAVE文件打开获取其中的声音数据,根据所需要的声音数据处理算法,进行相应的数学运算,然后将结果重新存储与WAVE格式的文件中去:可以使用CFILE类来实现 ...

  4. Node.js文件操作二

    前面的博客 Node.js文件操作一中主要是对文件的读写操作,其实还有文件这块还有一些其他操作. 一.验证文件path是否正确(系统是如下定义的) fs.exists = function(path, ...

  5. Java文件操作二:File文件的方法

    一.文件的判断方法 判断方法 .boolean canExecute()判断文件是否可执行 .boolean canRead()判断文件是否可读 .boolean canWrite() 判断文件是否可 ...

  6. servlet操作本地文件汇总: 判断文件是否存在;文件重命名;文件复制; 获取文件属性信息,转成Json对象; 获取指定类型的文件; 查找替换.txt中的文本

    package servlet; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; ...

  7. AIR文件操作(二):使用文件对象操作文件和目录

    转载于:http://www.flashj.cn/wp/air-file-operation2.html 文件对象是啥?文件对象(File对象)是在文件系统中指向文件或目录的指针.由于安全原因,只在A ...

  8. iOS学习之iOS沙盒(sandbox)机制和文件操作(二)

    1.获取程序的Home目录 NSString *homeDirectory = NSHomeDirectory(); NSLog(@"path:%@", homeDirectory ...

  9. PHP文件操作(二)-文件的读取

    1.fread()    //读取打开的文件 fread(file,length) file:必选项,规定要读取的打开的文件 length:必选项,规定要读取的最大字节数. <?php $fil ...

随机推荐

  1. Tkinter Message

    Python GUI - Tkinter Message(消息):这个小工具提供了一个多和不可编辑的对象,显示文本,自动断行和其内容的理由.   这个小工具提供了一个多和不可编辑的对象,显示文本,自动 ...

  2. day9-IO 番外

    同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的上下文下给出的答案是不同的.所以先限定一下本文的上下文. 本文讨论的背景是Linux环境下的network IO. ...

  3. 异步编程之Generator(2)——剖析特性

    异步编程系列教程: (翻译)异步编程之Promise(1)--初见魅力 异步编程之Promise(2):探究原理 异步编程之Promise(3):拓展进阶 异步编程之Generator(1)--领略魅 ...

  4. Memcached的过期数据的过期机制及删除机制(LRU)

    Memcached的过期数据的过期机制及删除机制1.当某个值过期后,并没有从内存删除,因此,使用stats命令统计时,curr_item参数有信息(不为0)2.当某个新值去占用他的位置时,当成空chu ...

  5. Rhythmk 一步一步学 JAVA (16) dom4j 操作XML

    1.项目文件结构图: 2.文件代码: doc.xml <?xml version="1.0" encoding="UTF-8"?> <Shop ...

  6. sql server 2005 修改动态端口,连接字符串为:需要改成:IP地址+逗号+端口号才行

    1.sql server 2005 安装完毕后,默认是动态段,需要用sql brower 查询端口号:修改给固定端口后,格式为:IP地址+逗号+端口号. 2.sql 2000 的格式为:格式为:IP地 ...

  7. C++builder 递归获取继承基类根类

    TClass ClassRef; ListBox1->Clear(); ClassRef = Sender->ClassType(); while (ClassRef != NULL) { ...

  8. Thread(线程)三

    今天我们继续接着线程讲讲,上一章提到一下task概念, 首先接着task继续往下讲,在前章节提到过Thread怎么实现其他线程完成后再让主线程继续执行的功能,那么如果Task也需要线程等待事件,该怎么 ...

  9. laravel phpstorm IDE 代码提示

    第一步:在项目的composer.json中添加如下一行 "require": { "laravel/framework": "5.0.*" ...

  10. nginx 多域名配置,采用多配置文件的方式

    nginx 中多域名配置,目前采用多配置文件的方式. 配置过程比较简单. 首先在 nginx 目录下创建子目录 vhosts . 在 vhosts 目录中创建对应域名的配置文件.如有域名 898hi. ...