Solved

How can I change Timestamp (creation & Modified dates) of a windows folder?

Posted on 2004-08-24
17
1,264 Views
Last Modified: 2008-01-09
How can I change Timestamp (creation & Modified dates) of a windows folder,
from a C program or using any tool?
0
Comment
Question by:chennarh
  • 6
  • 4
  • 2
  • +1
17 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11888573
You can do it with WinAPI SetFileTime() function, both in C and Visual Basic, but you have to specify which first.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/setfiletime.asp
0
 

Author Comment

by:chennarh
ID: 11888726
yes please. thanks
0
 

Author Comment

by:chennarh
ID: 11891738
I tried that, but it only worked for files, not for folders. I used these statements:

HANDLE destHandle = CreateFile(destFileName,GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS ,0);

result = SetFileTime(destHandle, &CreationTime,&LastAccessTime, &LastWriteTime);


Did you try that function successfully? If so, I appreciate if you can send sample source code. Thanks!
            
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11892367
Apparently there is a different behaviour with win 95/98. Take a look to this comment:
http://www.delphi3000.com/articles/article_3392.asp?SK=
0
 
LVL 3

Expert Comment

by:nichia
ID: 11945814
"Property Cafe changes file properties simply and quickly. It can rename files or change file attributes, time stamps, and extensions in batch mode." - Free to try; $9.00 to buy
http://www.download.com/Property-Cafe/3000-2248-10299975.html?tag=lst-0-5
0
 

Author Comment

by:chennarh
ID: 11970488
Property Cafe -  Did you try it for folder timestamp change?  I could not figure out how, when i drag&drop a folder, it changed timestamps for all files in the folder, but not for the folder itself.
Thanks!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:chennarh
ID: 12376382
Moderator,

I did not receive a valid solution. Please delete this question. Thanks!

chennarh
0
 
LVL 1

Expert Comment

by:tompyd
ID: 12469725
chennarh,
If you ever find a solution to this i hope you post it here.
I am looking to do the same thing and i was about to try everything you did to change the folder's time attribute.  Thanks for saving me a lot of lost time.
I agree that all of the proposed solutions here seem to indicate changing only a FILE's timestamp, not a FOLDER's timestamp.

Tom Pydeski
0
 
LVL 1

Accepted Solution

by:
tompyd earned 500 total points
ID: 12469920
Ok...I got it to work!
i used
Private Const FILE_FLAG_BACKUP_SEMANTICS = &H2000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3

hFile = CreateFile(strFolderName & Chr$(0), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, SECURITY_ATTRIBUTES, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0&)
Then use

GetFileTime(hFile, ftCreationTime, ftLastAccess, ftLastWrite)
'Convert
APIError = FileTimeToSystemTime(ftCreationTime, stCreationTime)
APIError = FileTimeToSystemTime(ftLastAccess, stLastAccess)
APIError = FileTimeToSystemTime(ftLastWrite, stLastWrite)

Finally to make the change
'Convert
APIError = SystemTimeToFileTime(stCreationTime, ftCreationTime)
APIError = SystemTimeToFileTime(stLastAccess, ftLastAccess)
APIError = SystemTimeToFileTime(stLastWrite, ftLastWrite)
SetFileTime(hFile, ftCreationTime, ftLastAccess, ftLastWrite)
0
 
LVL 1

Expert Comment

by:tompyd
ID: 12536651
I posted a complete example on Planet source code at:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=57174&lngWId=1
0
 

Author Comment

by:chennarh
ID: 12697038
tompyd,

Sorry for replying late, I did not realize you posted this solution.

I am not a VB expert, I am not able to compile the source code on the planet.... website, do you have a link for the executable?  Thanks!

chennarh
0
 
LVL 1

Expert Comment

by:tompyd
ID: 12833162
i can assemble it and send you the exe file, but you may be better off taking the source code and using it in your app (are you trying to code this in vb or C++?)
0
 

Author Comment

by:chennarh
ID: 12833603
Thank you tompyd! I appreciate that. I am a C/C++ guy, I tried to build your program in VB, but may be it needs someother components in addition to default VB6.0 installation, hence I quit trying. If you can send the exe (and any dlls) to chennarh@hotmail.com, that would be great! Thanks!

chennarh
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now