搜尋最新產生的檔案 |
|
superq
一般會員 發表:2 回覆:3 積分:1 註冊:2004-09-14 發送簡訊給我 |
|
pcboy
版主 發表:177 回覆:1838 積分:1463 註冊:2004-01-13 發送簡訊給我 |
提供兩個 Delphi 範例供參考 (可以知道大概流程 和 使用 Function 名稱)
// Delphi 7 Enterprise //複製文件夾: //下面兩個函數為文件拷貝函數: //拷貝目錄的遞歸輔助函數:DoCopyDir function DoCopyDir(sDirName:String;sToDirName:String):Boolean; var F: TSearchRec; //hFindFile:Cardinal; t,tfile:String; sCurDir:String[255]; FindFileData:WIN32_FIND_DATA; begin //先保存當前目錄 sCurDir:=GetCurrentDir; ChDir(sDirName); F.FindHandle:=FindFirstFile('*.*',FindFileData); if F.FindHandle<>INVALID_HANDLE_VALUE then begin if not DirectoryExists(sToDirName) then //如果目錄不存在 ForceDirectories(sToDirName); //強迫建立目錄 repeat tfile:=FindFileData.cFileName; if (tfile='.') or (tfile='..') then Continue; //跳過兩個目錄標識 if FindFileData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY then begin t:=sToDirName '\' tfile; if not DirectoryExists(t) then ForceDirectories(t); if sDirName[Length(sDirName)]<>'\' then DoCopyDir(sDirName '\' tfile,t) else DoCopyDir(sDirName tfile,sToDirName tfile); end else begin t:=sToDirName '\' tFile; CopyFile(PChar(tfile),PChar(t),false); end; until FindNextFile(F.FindHandle,FindFileData)=false; FindClose(F); end else begin ChDir(sCurDir); result:=false; exit; end; //回到原來的目錄下 ChDir(sCurDir); result:=true; end; //拷貝目錄的函數:CopyDir function CopyDir(sDirName:String;sToDirName:string):Boolean; begin if Length(sDirName)<=0 then exit; //拷貝... Result:=DoCopyDir(sDirName,sToDirName); end; end. ----------------------------------------------------------------- // 取得檔案日期範例 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure GetFileTime(const Tf:string); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function CovFileDate(Fd:_FileTime):TDateTime; var Tct:_SystemTime; Temp:_FileTime; begin FileTimeToLocalFileTime(Fd,Temp); FileTimeToSystemTime(Temp,Tct); CovFileDate:=SystemTimeToDateTime(Tct); end; procedure TForm1.GetFileTime(const Tf:string); const Model='yyyy/mm/dd,hh:mm:ss'; var Tp:TSearchRec; T1,T2,T3:string; begin FindFirst(Tf,faAnyFile,Tp); T1:=FormatDateTime(Model,CovFileDate(Tp.FindData.ftCreationTime)); { 傳回文件建立時間 } T2:=FormatDateTime(Model,CovFileDate(Tp.FindData.ftLastWriteTime)); { 傳回文件修改時間 } T3:=FormatDateTime(Model,Now); FindClose(Tp); Memo1.Clear; Memo1.Lines.Add(T1); Memo1.Lines.Add(T2); Memo1.Lines.Add(T3); end; procedure TForm1.FormCreate(Sender: TObject); begin GetFileTime('c:\Delphi 7.lnk'); end; end.
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案! 子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問! |
superq
一般會員 發表:2 回覆:3 積分:1 註冊:2004-09-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |