如何讀取文字檔的”建立日期”呢? |
答題得分者是:jow
|
老大仔
尊榮會員 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
[code delphi] procedure TForm1.Button2Click(Sender: TObject); var FileName: string; fh, FileDate: Integer; //File Handle FileDateTime: TDateTime; begin FileName := 'D:\RESULT.TXT'; if FileExists(FileName) then begin fh := FileOpen(FileName, fmOpenRead); if fh <> -1 then begin FileDate := FileGetDate(fh); FileDateTime := FileDateToDateTime(FileDate); Label1.Caption := FormatDateTime('YYYY-MM-DD hh:nn:ss', FileDateTime); FileClose(fh); end; end; end; [/code] [code delphi] procedure TForm1.Button3Click(Sender: TObject); var FileName: string; FileDate: Integer; FileDateTime: TDateTime; begin FileName := 'D:\RESULT.TXT'; if FileExists(FileName) then begin FileDate := FileAge(FileName); FileDateTime := FileDateToDateTime(FileDate); Label1.Caption := FormatDateTime('YYYY-MM-DD hh:nn:ss', FileDateTime); end; end; [/code] [code delphi] type TSortFileName = class public FileName: string; FileDateTime: TDateTime; function Key: string; end; function TSortFileName.Key: string; begin Result := FormatDateTime('YYYY-MM-DD hh:nn:ss', FileDateTime); end; procedure TForm1.Button4Click(Sender: TObject); var O: TSortFileName; Path: string; F: TSearchRec; L: TStringList; I: Integer; begin Path := 'D:\A'; L := TStringList.Create; try //Make TStringList Sorted... L.Sorted := True; //Find FileNames and Sort it using TStringList... if FindFirst(Path '\*.*', faAnyFile, F) = 0 then try repeat if (F.Name <> '.') and (F.Name <> '..') then begin O := TSortFileName.Create; O.FileName := Path '\' F.Name; O.FileDateTime := FileDateToDateTime(FileAge(O.FileName)); L.AddObject(O.Key, O); end; until FindNext(F) <> 0; finally FindClose(F); end; //Show Sorting Result... ListBox1.Clear; for I := 0 to L.Count-1 do begin O := TSortFileName(L.Objects[I]); ListBox1.Items.Add(O.Key ', ' O.FileName); end; finally //Free TSortFileName Objects, and TStringList itself... for I := 0 to L.Count-1 do L.Objects[I].Free; FreeAndNil(L); end; end; [/code] |
老大仔
尊榮會員 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |