2010. november 7., vasárnap
How to capture the date and time stamp of a file
Problem/Question/Abstract:
How to capture the date and time stamp of a file
Answer:
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
var
TheFileDate: string;
FHandle: integer;
begin
FHandle := FileOpen(YourFileName, 0);
try
TheFileDate := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));
finally
FileClose(FHandle);
end;
end;
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.
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése