|
| First/Last changed File in Folder | 
|
|---|
| First/Last accessed, First/Last created File of Folder | Product: Delphi all versions | Category: Files Operation | Skill Level:
 | Scoring:  | Last Update: 06/20/2002 | Search Keys: delphi delphi3000 article borland vcl code-snippet CompareFileTime, API, TFileTime | Times Scored: 1 | Visits: 2808 | Uploader: Holger Voigt Company: Mediakueche | Reference: N/A | | | Question/Problem/Abstract:
Sometimes its nessessary to know which File of an Folder was changed at the last. | Answer:
Sometimes its nessessary to know which File of an Folder was changed at the last. I wrote this function below. It can give you the File with the oldesd content too, if you set the parameter first := True. For the comparing I've used the API - Function CompareFileTime. If you wants to know the oldes or youngest created file or the last/first accessed file see the comments in the function.
Enjoy it.
Function GetLastOrFirstChangedFileOfFolder(First : Boolean; Folder : String): String;
var Ft1, Ft2 : TFileTime; sr :TSearchrec; what, Res : Integer;
begin
if not DirectoryExists(Folder) then exit;
if Folder[Length(Folder)] <> '\' then Folder := Folder + '\';
if First then What := 1 else What := -1;
res := FindFirst(Folder+ '*.*', faAnyFile, sr);
ft1 := sr.FindData.ftLastWriteTime;
//ft1 := sr.FindData.ftCreationTime; for the first/last created
//ft1 := sr.FindData.ftLastAccessTime; for the first/last access
Result := sr.Name;
while res = 0 do
begin
Ft2 := sr.FindData.ftLastWriteTime;
//ft1 := sr.FindData.ftCreationTime; for the first/last createt
//ft1 := sr.FindData.ftLastAccessTime; for the first/last access
if CompareFileTime(ft1, ft2) = What then begin
ft1 := Ft2;
Result := sr.Name;
end;
res := FindNext(sr);
end;
FindClose(sr);
end;
|
|
|
| |
Sign up to consume product discounts for Bronze memberships !
|
|
| |
Community Ad of R. Lefter |
|
| |
|
|
|