Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting file creation time 1

Status
Not open for further replies.

shuesty

Programmer
Jul 10, 2004
15
DE
I'm working on a project that involves downloading files via ftp sites ... parsing out the needed data ... then adding the data to a database. The files are expected to be updated everyday so that I'm not putting the same data into the database however I was wondering if there was a way to find out the creation time of the file so that I don't download a file I already have. I'm using the IdFTP object so references to that would be preferable.

Thank you kindly,
Shuesty
 
Try this:
Code:
var
  age: Integer;
  date: TDateTime;
begin
  age := FileAge('C:\TEMP.PDF');
  if age <> -1 then
    date := FileDateToDateTime(age);
  ShowMessage(DateToStr(date));
end;

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Well it gives me the creation date of the file which is helpful. Unfortunately I need the date (and time) that the file was placed onto the FTP site. Any ideas for that??

Shuesty
 
This may help

FTP: TIdFTP;

FTP.Connect(TRUE, 1800000);
Files := TStringList.Create;
FTP.List(Files, '*.txt', True);
for i := 0 to FTP.DirectoryListing.Count-1 do
showmessage(datetimetostr(FTP.DirectoryListing.Items.ModifiedDate));

 
I'm wondering what version of Borland you are using because with 6.0 I don't have the FTP.DirectoryListing attribute. I have a work around already formulating though so thanks for the help.

Shuesty
 
WARNING: FileAge() does not get creation time but returns the last modification time. Functions below get CREATION time.

Code:
function SNL_FileTime2DateTime(FileTime: TFileTime): TDateTime;
var
   LocalFileTime: TFileTime;
   SystemTime: TSystemTime;
begin
   FileTimeToLocalFileTime(FileTime, LocalFileTime) ;
   FileTimeToSystemTime(LocalFileTime, SystemTime) ;
   Result := SystemTimeToDateTime(SystemTime) ;
end;

function GetFileCreationTime(FileName: string): TDateTime;
var
   MyRec: TSearchRec;
begin
   Result := Now;

   if (FindFirst(FileName, faAnyFile, MyRec) = 0) then
   begin
      Result := SNL_FileTime2DateTime(MyRec.FindData.ftCreationTime);
      FindClose(MyRec);
   end;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top