2010. november 7., vasárnap

How to capture the date and time stamp of a file


How to capture the date and time stamp of a file


Would you like to display a file's date and/or time stamp to your user? There isn't a single Delphi function that does this on its own. However, we can combine two functions to get the results we want. First, the FileGetDate function returns the DOS date-time stamp of the file specified by its handle, Fhandle. Then, the FileDateToDateTime function translates the integer into a TDateTime value. Finally, the DateTimeToStr procedure converts the TDateTime value into a string.

procedure TForm1.Button1
  TheFileDate: string;
  FHandle: integer;
  FHandle := FileOpen(YourFileName, 0);
    TheFileDate := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));

Use formatting parameters DateTimeToStr to refine the output. Even if you don't have to display the time and date, you can use this technique to perform comparisons and calculations on file dates.

Nincsenek megjegyzések:

Megjegyzés küldése