Solved

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

Posted on 2004-08-24
17
1,263 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
Comment Utility
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
Comment Utility
yes please. thanks
0
 

Author Comment

by:chennarh
Comment Utility
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
Comment Utility
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
Comment Utility
"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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:chennarh
Comment Utility
Moderator,

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

chennarh
0
 
LVL 1

Expert Comment

by:tompyd
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

10 Experts available now in Live!

Get 1:1 Help Now