Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
495 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


First/Last changed File in FolderFormat this article printer-friendly!Bookmark function is only available for registered users!
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:
2631
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;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
C.A. Longen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)