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. Python与快速排序

    这个算法系列主要是自己学习算法过程中动手实践一下,写这个文章作为笔记和分享个人心得,如有错误请各位提出. 注:转载请说明出处 问题提出: 将以下数据升序排列:5, 2, 8, 6, 4, 9, 7, ...

  2. 关于1.0.0版Backbone.js调用validate

    网上的调用这个方法的例子都是老版本的,新版本的调用方法有所变化,首先错误绑定事件error换成了invalid,其次设置数据时应传入{validate: true} var Chapter = Bac ...

  3. 高效率terminal和sublime 相互启动

    在日常的工作中,我们经常使用到terminal和Sublime .今天给大家介绍下怎样高效率的实现terminal和sublime 相互启动 (这里说的是MAC环境,我用的是Sublime Text ...

  4. 用django实现redirect的几种方法总结

    用django开发web应用, 经常会遇到从一个旧的url转向一个新的url.这种隐射也许有规则,也许没有.但都是为了实现业务的需要.总体说来,有如下几种方法实现 django的 redirect.1 ...

  5. PHP - 引用计数

    引用计数以及是否是引用变量,一个神奇的函数,查看当前引用计数: <?php xdebug_debug_zval('a'); 以上例程会输出: a: (refcount=1, is_ref=0)= ...

  6. 使用ConfigFilter

    ConfigFilter的作用包括: 从配置文件中读取配置 从远程http文件中读取配置 为数据库密码提供加密功能 1 配置ConfigFilter 1.1 配置文件从本地文件系统中读取 <be ...

  7. k8s v1.5.8 单节点搭建

    setsid etcd -name etcd -data-dir /var/lib/etcd -listen-client-urls http://0.0.0.0:2379,http://0.0.0. ...

  8. Perl 获取时间函数

    Perl 时间日期 Perl中处理时间的函数有如下几种:    1.time() 函数:返回从1970年1月1日起累计的秒数    2.localtime() 函数:获取本地时区时间(多用这个)    ...

  9. mybatis+oracle如何批量执行多条update

    接口 public void setStatus(List<Columns> columnsList); mapping xmlmapping 中使用foreach,关于标签的使用,资料非 ...

  10. Python实现常见算法[2]——快速排序

    #!/usr/bin/python # module: quik_sort.py def PARTION(L,m,n): base = L[n] i = m-1 j = m while j<n: ...