Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
First / Last changed File in Folder Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
18-Jun-03
Category
Files Operation
Language
Delphi 2.x
Views
76
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Holger Voigt

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. 
1   
2   function GetLastOrFirstChangedFileOfFolder(First: Boolean; Folder: string): string;
3   var
4     Ft1, Ft2: TFileTime;
5     sr: TSearchrec;
6     what, Res: Integer;
7   begin
8     if not DirectoryExists(Folder) then
9       exit;
10    if Folder[Length(Folder)] <> '\' then
11      Folder := Folder + '\';
12    if First then
13      What := 1
14    else
15      What := -1;
16    res := FindFirst(Folder + '*.*', faAnyFile, sr);
17    ft1 := sr.FindData.ftLastWriteTime;
18    //ft1 := sr.FindData.ftCreationTime;   for the first/last created
19    //ft1 := sr.FindData.ftLastAccessTime;  for the first/last access
20    Result := sr.Name;
21    while res = 0 do
22    begin
23      Ft2 := sr.FindData.ftLastWriteTime;
24      //ft1 := sr.FindData.ftCreationTime;   for the first/last createt
25      //ft1 := sr.FindData.ftLastAccessTime;  for the first/last access
26      if CompareFileTime(ft1, ft2) = What then
27      begin
28        ft1 := Ft2;
29        Result := sr.Name;
30      end;
31      res := FindNext(sr);
32    end;
33    FindClose(sr);
34  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC