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. Drools简单例子

    转自:http://www.blogjava.net/diggbag/articles/359347.html 1.Drools简单例子 首先是搭建一个可供进行Drools开发的框架.Jboss官方推 ...

  2. sql之分段统计

    sql之分段统计 需求:获取一个县所有家庭人数在1-2人,3-4人,5-6人,6人以上的家庭数的数组 思路:通过CASE WHEN 将 CBFCYSL分组,然后统计数据条数. 语句: SELECT T ...

  3. jq循环方法

    jq在前台使用很广泛,其中不可避免会用到循环,for循环可以,但有时不方便,下边举两个jq循环: 第一个: $.each(数组或对象,function(index,item){ //循环的逻辑代码 } ...

  4. Elasticsearch-PHP 快速开始

    快速开始 本章节会给你一个客户端的主要功能(函数)是如何工作的快速概述. 安装 引入(包含)elasticsearch-php 在你的 composer.json 文件: { "requir ...

  5. Linux常用命令----基本文件系统常用命令

    1.查看当前工作目录---pwd sunny@sunny-ThinkPad-T450:~$ pwd /home/sunny sunny@sunny-ThinkPad-T450:~$ cd Worksp ...

  6. 你不知道的高性能Javascript

    想必大家都知道,JavaScrip是全栈开发语言,浏览器,手机,服务器端都可以看到JS的身影. 本文会分享一些高效的JavaScript的最佳实践,提高大家对JS的底层和实现原理的理解. 数据存储 计 ...

  7. ShaderLab内置变量

    [ShaderLab内置变量]

  8. go_条件和循环

    package main import ( "io/ioutil" "fmt") func grade(score int) string{ g:=" ...

  9. Android中的网络编程

    谷歌在Android6.0之后就废弃了使用HttpClinet进行网络连接.所以,这里需要重点学习的是通过HttpUrlConnect进行网络连接. String path="这里是你想要的 ...

  10. Web内容回顾

    -----------------siwuxie095 Java EE 三层结构 1.Web 层:Struts2 框架 2.Service 层:Spring 框架 3.DAO 层:Hibernate ...