Click here to Skip to main content
Licence CPOL
First Posted 27 Nov 2008
Views 37,588
Downloads 1,467
Bookmarked 25 times

Change File Date Attributes

By Etienne Rached | 27 Nov 2008
Change created, modified and accessed time

1

2
1 vote, 7.7%
3
8 votes, 61.5%
4
4 votes, 30.8%
5
4.20/5 - 13 votes
1 removed
μ 4.11, σa 1.01 [?]

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.

ChangeFileDateAttributes_Open.png

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.

ChangeFileDateAttributes_Modify.png

Click Save and the new attributes will be saved into the file.

ChangeFileDateAttributes_Save.png

The file attributes will look like the following:

ChangeFileDateAttributes_Properties.png

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:

//Change the file created time.
File.SetCreationTime(path, dtCreation);
//Change the file modified time.
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Etienne Rached

Software Developer

Lebanon Lebanon

Member

Follow on Twitter Follow on Twitter


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAdding AM or PM to CustomFormat PinmemberJohn Jasper12:38 13 Aug '09  
QuestionHow to change last saved date? PinmemberMember 46863641:14 9 Jul '09  
GeneralChanging more than one file's date. Pinmemberdbett17:35 8 Feb '09  
GeneralRe: Changing more than one file's date. PinmemberEtienne Rached14:55 17 Feb '09  
Generalexecuting the program Pinmemberjim sladge6:12 6 Jan '09  
GeneralRe: executing the program [modified] PinmemberEtienne Rached16:54 10 Jan '09  
QuestionConsistency of dates ? Pinmemberrob tillaart23:14 2 Dec '08  
AnswerRe: Consistency of dates ? PinmemberDennis Dykstra5:19 5 Dec '08  
AnswerRe: Consistency of dates ? PinmemberEtienne_CodeProject18:52 16 Dec '08  
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.
GeneralRe: Consistency of dates ? Pinmemberrob tillaart20:44 16 Dec '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 27 Nov 2008
Article Copyright 2008 by Etienne Rached
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid