![]() |
|
||||||||||||||
| | 网站首页 | 数据库教程 | web编程 | 服务器 | 程序设计 | | ||
|
||
|
|||||
| 取得一个文件夹下的文件,并保存在一个文件中. | |||||
作者:佚名 文章来源:不详 点击数: 更新时间:2007-9-12 ![]() |
|||||
|
正在装载数据…… //文件时间转DateTime function FileTimeToDateTime(const AFileTime:TFileTime):TDateTime; var SYSTime:TSystemTime; begin if FileTimeToSystemTime(AFileTime,SYSTime) then Result:=SystemTimeToDateTime(SYSTime) else Result:=0; end; function PathRelativePathTo(pszPath:LPSTR; pszFrom:LPCSTR; dwAttrFrom:DWORD; pszTo:LPCSTR; dwAttrTo:DWORD):BOOL; stdcall; external "shlwapi.dll " name "PathRelativePathToA "; //取得相对路径 function GetFileRelativePath(CurPath:string; const Dest:string; const NoDot:Boolean=False):string; var ResultPath: array[0..1024] of Char;//路径转换结果 begin CurPath:=ExtractFileDir(CurPath)+ " "; if PathRelativePathTo(ResultPath, PChar(CurPath), FILE_ATTRIBUTE_DIRECTORY, PChar(Dest), FILE_ATTRIBUTE_DIRECTORY) then begin Result := ResultPath; if NoDot then Result:=Copy(Result,3,Length(Result)-2); end else Result := Dest; end; //得到文件列表 procedure GetFileList(const aDir,aFilter:string; const FileName:TFileName;AbSolutePath:Boolean=True;Recursion:Boolean=False); {aDir:文件路径. aFilter:通配符(所有文件则*.*).FileName:输出文件名;AbSolutePath:使用绝对路径;Recursion:是否递归搜索} var aList:TStringList; procedure AddFiles(TmpDir:string); var SR:TSearchRec; Dir:string; FileDir:string; begin Dir:=IncludeTrailingPathDelimiter(TmpDir); if AbSolutePath then FileDir:=Dir else FileDir:=GetFileRelativePath(IncludeTrailingPathDelimiter(aDir),Dir,True); if FindFirst(Dir+aFilter,faAnyFile,SR)=0 then begin repeat if (SR.Name < > ". ") and (SR.Name < > ".. ") then begin if SR.Attr=faDirectory then begin if Recursion then AddFiles(Dir+SR.Name); end else aList.Add(FileDir+SR.Name+#9#9+ FormatDateTime( "yyyy-mm-dd hh:nn:ss ",FileTimeToDateTime(SR.FindData.ftLastWriteTime))); end; until FindNext(SR) < >0; SysUtils.FindClose(SR); end; end; begin aList:=TStringList.Create; try AddFiles(aDir); aList.SaveToFile(FileName); finally aList.Free; end; end; //使用方法: procedure TForm1.btn2Click(Sender: TObject); begin //文件保存在D:\abc.txt GetFileList(Edit1.Text, "*.* ", "D:\abc.txt ",chkbx2.Checked,chkbx1.Checked); end; 本文来源:http://blog.csdn.net/mastersky/archive/2007/08/21/1752585.aspx
|
|||||
| 文章录入:admin 责任编辑:admin | |||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 网站地图 | 管理登录 | | |||
|