Solved

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

Posted on 2004-08-24
17
1,268 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 293
Visual Studio 2005 text editor 10 49
Create Files based on Cell Values in a Range in Excel 12 44
Macro problems with Excel file 6 27
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

730 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