Introduction
Have you ever found yourself in a situation where you wanted to change the attributes of a file such as the creation date, modified date or last accessed date.
For one reason or another, sometimes you might just want to change the attributes, and since Windows does not offer an easy way to do so, I wrote a small easy-to-use program to change the date of a file.
Using the Program
After extracting and executing the program, click open and load the file for which you want to change the attributes.
After you open the file, you will see its path in the textbox in the bottom of the program.
Now all you have to do is just click on the checkbox that you wish to edit, and select a new time and date.
Click Save and the new attributes will be saved into the file.

The file attributes will look like the following:
Using the Code
I will explain just the functions required to change the date attributes.
First we add the IO library:
using System.IO;
Then we get the path of the file:
string path="";
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
path = dialog.FileName;
}
Then we create the DateTime object:
DateTime dtCreation = new DateTime(2007, 10, 2, 2, 19, 33);
DateTime dtModified = new DateTime(2008, 11, 4, 2, 23, 4);
And we assign it to the file:
File.SetCreationTime(path, dtCreation);
File.SetLastWriteTime(path, dtModified);
Conclusion
I wrote this small program for a friend of mine who wanted to change the date of a file and didn't know any easy way to do it. Please feel free to reply or ask any question(s).
History
- 27th November, 2008: Initial post
|
|
 |
 | Adding AM or PM to CustomFormat John Jasper | 12:38 13 Aug '09 |
|
 |
I appreciate your posting this utility. Just what I needed with one small exception.
After examing changed file attributes, the date format for your application was missing an option for AM and PM values. This could be done by changing the CustomFormat properties for the (3) datetime picker controls by adding "tt": was this format hh:mm:ss dddd MMMM dd, yyyy and changed to hh:mm:ss tt dddd MMMM dd, yyyy
|
|
|
|
 |
 | How to change last saved date? Member 4686364 | 1:14 9 Jul '09 |
|
 |
In Vista there is one more attribute for file is last saved date. How to do that? I could not find any option in VS 2008 also.
|
|
|
|
 |
 | Changing more than one file's date. dbett | 17:35 8 Feb '09 |
|
 |
Hey Etienne, do you think you can make your program change the date of more than 1 file?
Thank You for your time...Dbett
|
|
|
|
 |
|
 |
Hey Dbett,
I think this is a great idea, i will modify the program soon in order to support multiple files at the same time 
Thank you.
|
|
|
|
 |
 | executing the program jim sladge | 6:12 6 Jan '09 |
|
 |
Maybe this is a dumb question, but how do I execute the program?
|
|
|
|
 |
|
 |
Hey Jim,
You have to download the demo project, then extract it using a program like winzip (www.winzip.com), then execute the .exe program
modified on Sunday, January 11, 2009 12:49 AM
|
|
|
|
 |
 | Consistency of dates ? rob tillaart | 23:14 2 Dec '08 |
|
 |
Hi Etienne,
With your application it is possible to set a creation date after the modification date. The application should warn the user if this occurs. The user might have a good reason for this but except for time traveling files the modification date should be after creation date. BTW: setting the accesdate back in time did not work.
reagrds, rob
|
|
|
|
 |
|
 |
Actually, Windows already does this. If you have a file in which the creation date and modified dates are the same, and then two days later you copy the file to a thumb drive and then to a different computer, the creation date on the new computer will be later than the modified date. Windows gives you no warning about this and I really doubt that it bothers anyone very much.
|
|
|
|
 |
|
 |
hy Rob,
Concerning warning the user about setting the creation date after the modification date, I did not see a good reason to make it, as Dennis stated in his reply too, usually when you copy a file to a new location, whether it was on the same disk or CD/DVD or any other storage device, the creation date will be set to the current date, while the modification date will not be modified, so i saw no reason for creating such an option, however if you sill would like to have such an option, i would gladly modify the application and include such an option.
As for the access date, it is working fine with me, can you please let me know where the problem is occurring exactly? btw, usually when you open a file or just access it, the access time will be modified directly by the operating system to the current time.
|
|
|
|
 |
|
 |
Hi Etienne,
With the accesstime, the change holds only for the last access. If I change the accesstime of a file to e.g. dec 12 it will correctly show so if I ask properties of the file. If I ask them a second time the accesstime is changed to today. So just looking at the properties of the file changes it's properties. It's Windows behavior, not your application.
With respect to the modification/creation time I understand that you have to deal with Windows behavior. In the "requirements-world" there is always a (fundamental?) discussion about how far one should go in guiding and protecting the user to prevent mistakes. There are actions that are irreversable e.g. permanent delete, then a warning definitely makes sense. The change of the modification date is not irreversable, but it might introduce a semantic inconsistency. It depends on the application if this is a serious problem or not. And Dennis is right,most apps don't care.
Thanks for your time, rob
|
|
|
|
 |
|
|