Beranda > Delphi > Setting the modified date of a file

Setting the modified date of a file

Sometimes you want to set your files’ modified dates before shipping the final product to your customers, much like Borland does for the date/time stamps of the BDE files and Delphi binary files.  Read the comment below to see how to use it.procedure SetModifyDate(fName, fDate: string);
{ Proc to modify the Modify Date of a file.                            }
{ Usage: SetModifyDate(‘C:\Temp\SomeFile.txt’, ’12/31/1998 00:00:00′); }
var
  Age,
  FHandle: integer;
  LocalFileTime,
  FileTime: TFileTime;
  FileBuf: file;
begin
  if FileExists(fName) then
    begin
      AssignFile(FileBuf, fName);
      Reset(FileBuf);
      try
        Age := DateTimeToFileDate(StrToDateTime(fDate));
        FHandle := TFileRec(FileBuf).Handle;
        DosDateTimeToFileTime(LongRec(Age).Hi, LongRec(Age).Lo, LocalFileTime);
        LocalFileTimeToFileTime(LocalFileTime, FileTime);
        // to set the files’ last modified date
        SetFileTime(FHandle, nil, nil, @FileTime);
        // to set the files’ created date
        SetFileTime(FHandle, @FileTime, nil, nil);
        // to set the files’ last accessed date
        SetFileTime(FHandle, nil, @FileTime, nil);
      finally
        CloseFile(FileBuf);
     end;
    end
  else
    MessageDlg(‘File does not exist: ‘ + fName, mtError, [mbOK], 0);
end;

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: