文件查找记录类型 - TSearchRec - 文件操作(二)
来源:互联网 发布:淘宝手机尺寸是多少604 编辑:程序博客网 时间:2024/06/05 21:56
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 := 0 to S_FileList.Count - 1 do begin if FindFirst(S_Path + S_FileList[I],faAnyFile,FileRec) = 0 then repeat if ((FileRec.Attr and faDirectory) <> 0) 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) = 0) then begin TmpList.Add(S_Path + FileRec.Name); TmpList.Add('FileRec.Size:' + IntToStr(FileRec.Size));<span style="white-space:pre"></span>//文件大小 TmpList.Add('FileRec.Name:' + FileRec.Name);<span style="white-space:pre"></span>//文件名 TmpList.Add('FileRec.Attr:' + IntToStr(FileRec.Attr));<span style="white-space:pre"></span>//文件属性 TmpList.Add('FileRec.ExcludeAttr:' + IntToStr(FileRec.ExcludeAttr));<span style="white-space:pre"></span>//未知 TmpList.Add('FileRec.FindHandle:' + IntToStr(FileRec.FindHandle));<span style="white-space:pre"></span>//文件句柄 FileTimeToLocalFileTime(FileRec.FindData.ftCreationTime,FileTime);<span style="white-space:pre"></span>//文件创建时间 FileTimeToSystemTime(FileTime,SysTime); TmpList.Add('FileRec.FindData.ftCreationTime:' + DateTimeToStr(SystemTimeToDateTime(SysTime))); FileTimeToLocalFileTime(FileRec.FindData.ftLastAccessTime,FileTime);<span style="white-space:pre"></span>//文件最后 ?? 时间<span style="white-space:pre"></span> FileTimeToSystemTime(FileTime,SysTime); TmpList.Add('FileRec.FindData.ftLastAccessTime:' + DateTimeToStr(SystemTimeToDateTime(SysTime))); FileTimeToLocalFileTime(FileRec.FindData.ftLastWriteTime,FileTime);<span style="white-space:pre"></span>//文件最后修改时间 FileTimeToSystemTime(FileTime,SysTime); TmpList.Add('FileRec.FindData.ftLastWriteTime:' + DateTimeToStr(SystemTimeToDateTime(SysTime))); TmpList.Add('FileRec.FindData.nFileSizeHigh:' + FloatToStr(FileRec.FindData.nFileSizeHigh));<span style="white-space:pre"></span>//文件大小Hight值 TmpList.Add('FileRec.FindData.nFileSizeLow:' + FloatToStr(FileRec.FindData.nFileSizeLow)); TmpList.Add('FileRec.TimeStamp:' + DateTimeToStr(FileRec.TimeStamp));<span style="white-space:pre"></span>//实际值=文件最后修改时间<pre name="code" class="delphi"> end; end; until FindNext(FileRec) <> 0; 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
0 1
- 文件查找记录类型 - TSearchRec - 文件操作(二)
- TSearchRec
- Ubuntu查找文件操作
- MASM-文件记录操作
- 文件操作记录
- C#操作文件记录
- Linux入门(二)文件查找
- linux文件查找及操作
- Linux-基本操作-查找文件
- 文件操作(二)
- MFC文件操作二
- 文件操作二
- Java文件操作(二)
- Python文件操作二
- shell文件操作(二)
- 文件操作二
- 文件操作(一)(二)
- delphi中操作记录文件
- C++拾遗--目录
- 大数据术语入门整理
- PHP中::、->、self、$this操作符的区别
- UVa 12096 map ,vector,set,string ,stack的混用
- free问题之注意点
- 文件查找记录类型 - TSearchRec - 文件操作(二)
- 菜鸟的Linux学习笔记之命令whereis
- 44444444444444
- matlab关键字
- MiniGUI应用程序使用 Ctrl+c 结束进程,发现产生core文件
- 在javascript中一下值被当做false
- MD5 Tool 工具类
- vi使用总结
- 中国经济走出困局的最后选择--刘胜军