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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change date of creation of a folder...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hey,

how can I change the creation date/time of a directory; I tried the following, but it doesn't work
Code:
if (CreateFile('C:\test\',
     GENERIC_READ + GENERIC_WRITE,
     FILE_SHARE_READ,
     nil,
     OPEN_EXISTING,
     FILE_ATTRIBUTE_DIRECTORY+FILE_FLAG_BACKUP_SEMANTICS,
     0) = INVALID_HANDLE_VALUE) then
  ShowMessage('Invalid handle');

("SetFileTime" always needs the handle from above which weirdly is invalid)

Tim
 
As far as I know, you can only change the modification time: not the creation time. The easiest way to set the creation time is to set the system time, then create the file, and then set it back to what it used to be.
 
Hey,

problem is that I want to change the date of an existing folder and I don't want to create one.

CreateFile function doesn't work as it is described in MSDN, I get wrong handles.

With "SetFileTime (handle, *Creation, *Modify, *Access);"
everything is fine, when I use a file with the "handle", but after trying to retrive the handle of an existing folder I get an invalid handle and SetFileTime fails in consequence, too.

Tim
 
I'm sure you know this, and its probably correct in your actual code, but you need == instead of = in your statement if your trying to compare stuff instead of asign a value.
 
@Jonsauce:

I'm sorry I tried the source in Delphi so I posted the non-C source, thus it correctly would looks like this:

Code:
if (CreateFile("C:\test\",
     GENERIC_READ | GENERIC_WRITE,
     FILE_SHARE_READ |FILE_SHARE_WRITE,
     nil,
     OPEN_EXISTING,
     FILE_ATTRIBUTE_DIRECTORY+FILE_FLAG_BACKUP_SEMANTICS,
     NULL) == INVALID_HANDLE_VALUE)
{
  MessageBox (NULL, "Invalid handle!", "Wrong handle", MB_OK); 
}
else
{
  SetFileTime (handle, &Creation, &Modify, &Access);
}

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top