Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1280
  • Last Modified:

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

How can I change Timestamp (creation & Modified dates) of a windows folder,
from a C program or using any tool?
0
chennarh
Asked:
chennarh
  • 6
  • 4
  • 2
  • +1
1 Solution
 
Jaime OlivaresCommented:
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
 
chennarhAuthor Commented:
yes please. thanks
0
 
chennarhAuthor Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jaime OlivaresCommented:
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
 
nichiaCommented:
"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
 
chennarhAuthor Commented:
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
 
chennarhAuthor Commented:
Moderator,

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

chennarh
0
 
tompydCommented:
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
 
tompydCommented:
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
 
tompydCommented:
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
 
chennarhAuthor Commented:
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
 
tompydCommented:
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
 
chennarhAuthor Commented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now