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. 25_java之Properities集合|对象序列化和反序列化

    01Properties集合的特点 * A: Properties集合的特点 * a: Properties类介绍 * Properties 类表示了一个持久的属性集.Properties 可保存在流 ...

  2. Notes About Singular Value Decomposition

    A brief summary of SVD: An original matrix Amn is represented as a muliplication of three matrices: ...

  3. 在Android Studio 0.5.2中使用ArcGIS Android SDK

    环境 操作系统:Mac OSX 10.8.5Android Studio: 0.5.2ArcGIS Android SDK: 10.2.3 操作步骤 在Android Studio中新建一个Modul ...

  4. Mysql在spring中jdbc.properties连接配置

    ############################## mysql的数据源 ############################## jdbc.driver=com.mysql.jdbc.D ...

  5. MyBatis 学习记录2 Mapper对象是如何生成的

    主题 以前我一直有一个问题不懂.并且觉得很神奇.就是Mybatis我们开发的时候只需要定义接口,并没有写实现类,为什么我们运行的时候就可以直接使用? 现在我想分享下这部分大致是怎么实现的. 在启动的时 ...

  6. java中执行子类的构造方法时,会不会先执行父类的构造方法

    会,在创建子类的对象时,jvm会首先执行父类的构造方法,然后再执行子类的构造方法,如果是多级继承,会先执行最顶级父类的构造方法,然后依次执行各级个子类的构造方法.

  7. 团队合作的Ground Rules

    在每个Sprint中,我们会为Sprint的确定DOD(Definition of Done,完成的定义).在团队成员合作的过程中,我们也需要定义合作规则,这就是Ground rules,就像小学生守 ...

  8. CBCentralManagerDelegate Protocol 委托协议相关分析

    总体概述 CBCentralManagerDelegate 协议中定义了一系列方法列表,这些方法是委托对象必须要实现的方法(也有可选择的),当中央管理器的相应变化就会调用委托对象中实现的相应方法. M ...

  9. PHP获取页面执行时间的方法(推荐)

    一些循环代码,有时候要知道页面执行的时间,可以添加以下几行代码到页面头部和尾部: 头部:$stime=microtime(true); 尾部: $etime=microtime(true);//获取程 ...

  10. JAVA中的数组对象

    代码:Student [] sd=new Student[5];//新建一个学生类的数组对象sd.        sd[0]=new Student("kj",13);//为数组对 ...