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. mac 上sed

    mac上sed和liunx是不一样的,所以有些指令可能不通用,需要将mac上sed替换成gun的: Install Homebrew First, visit Homebrew homepage an ...

  2. Python操作中缓存Redis

    Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorte ...

  3. 记一则css3计算

    .Head{ background-image: url("../../Img/PersonalCenter/banner.png"); background-repeat: no ...

  4. 125. Valid Palindrome (Array; Two-Pointers)

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  5. 获取时间【NSDate】

    [Objective-C]NSDate详解及获取当前时间等常用操作 博客分类: Objective-C objective-cnsdate  NSDate类用于保存时间值,同时提供了一些方法来处理一些 ...

  6. HEIDSOFT

    HEIDSOFT ENTHUSIASTIC GITHUB USER heidsoft@sina.com GitHub Profile I'm a developer based in China.sh ...

  7. webapi限流框架WebApiThrottle

    为了防止网站意外暴增的流量比如活动.秒杀.攻击等,导致整个系统瘫痪,在前后端接口服务处进行流量限制是非常有必要的.本篇主要介绍下Net限流框架WebApiThrottle的使用. WebApiThro ...

  8. ServiceStack.redis用法

    using System; using System.Collections.Generic; using ServiceStack.Redis; namespace SysBuild { class ...

  9. sql复制表结构,复制表内容语句

    sql复制表结构,复制表内容语句 select * into b from a where 1<>1 select top 0 * into b from a insert into a ...

  10. 黑盒测试实践-任务进度-Day05

    任务进度11-30 使用工具 selenium 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务进度 经过了前两天的学习任务的安排,以下是大家的任务进度: 华同学(任务1) 1.由于昨天 ...