frangers99
asked on
Date and Time
I want to set the last access/modify/create details of a file to a specified date - let's say 18th December 1998 - by clicking on a button.
I found this information in the Win32 help file, but i am unsure how to use this in delphi.
----// start win32 help file //----
The SetFileTime function sets the date and time that a file was created, last accessed, or last modified.
BOOL SetFileTime(
HANDLE hFile, // identifies the file
CONST FILETIME *lpCreationTime, // time the file was created
CONST FILETIME *lpLastAccessTime, // time the file was last accessed
CONST FILETIME *lpLastWriteTime // time the file was last written
);
Parameters
hFile
Identifies the file for which to set the dates and times. The file handle must have been created with GENERIC_WRITE access to the file.
lpCreationTime
Points to a FILETIME structure that contains the date and time the file was created. This parameter can be NULL if the application does not need to set this information.
lpLastAccessTime
Points to a FILETIME structure that contains the date and time the file was last accessed. The last access time includes the last time the file was written to, read from, or (in the case of executable files) run. This parameter can be NULL if the application does not need to set this information.
lpLastWriteTime
Points to a FILETIME structure that contains the date and time the file was last written to. This parameter can be NULL if the application does not want to set this information.
---// end win32 help file //----
specifically how do i setup the FILETIME structure... for that matter if i know the date i want to set am i required to do that???
thanks for your help.
I found this information in the Win32 help file, but i am unsure how to use this in delphi.
----// start win32 help file //----
The SetFileTime function sets the date and time that a file was created, last accessed, or last modified.
BOOL SetFileTime(
HANDLE hFile, // identifies the file
CONST FILETIME *lpCreationTime, // time the file was created
CONST FILETIME *lpLastAccessTime, // time the file was last accessed
CONST FILETIME *lpLastWriteTime // time the file was last written
);
Parameters
hFile
Identifies the file for which to set the dates and times. The file handle must have been created with GENERIC_WRITE access to the file.
lpCreationTime
Points to a FILETIME structure that contains the date and time the file was created. This parameter can be NULL if the application does not need to set this information.
lpLastAccessTime
Points to a FILETIME structure that contains the date and time the file was last accessed. The last access time includes the last time the file was written to, read from, or (in the case of executable files) run. This parameter can be NULL if the application does not need to set this information.
lpLastWriteTime
Points to a FILETIME structure that contains the date and time the file was last written to. This parameter can be NULL if the application does not want to set this information.
---// end win32 help file //----
specifically how do i setup the FILETIME structure... for that matter if i know the date i want to set am i required to do that???
thanks for your help.
ASKER
wow that was quick! thanks. Only problem is it doesnt change the last accessed property...is that possible?
ASKER
wow that was quick! thanks. Only problem is it doesnt change the last accessed property...is that possible?
Hmmm.... it should change it....
i wonder if fileClose(f) isn't overwriting the last accessed attr?
GL
Mike
GL
Mike
ugh, didn't quite finish my thought :). If setFileTime needs a file handle created with GENERIC_WRITE access then closing the handle will almost certainly update the access rec. Quickly perusing the win32.hlp I don't seen another api for setting file times. I ams wondering if you might have to open the files, change the system date/time, close the file & restore the system date/time. A real kludge, and not really a good practice, perhaps someone else can think of a better way - if I'm not completely wrong here.
GL
Mike
GL
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what can i say! thanks.
function FileSetCreationDate(Handle
var
LocalFileTime, FileTime: TFileTime;
begin
Result := 0;
if DosDateTimeToFileTime(Long
LocalFileTimeToFileTime(Lo
SetFileTime(Handle, @FileTime, @FileTime, @FileTime) then Exit;
Result := GetLastError;
end;
procedure TForm1.Button1Click(Sender
var f: Integer;
begin
f := FileOpen('c:\myfiles\test.
FileSetCreationDate(f, DateTimeToFileDate(EncodeD
FileClose(f);
end;