[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-08-24
17
Medium Priority
?
1,278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 

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 2000 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

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!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 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