Click here to Skip to main content
12,077,351 members (46,671 online)
Click here to Skip to main content
Add your own
alternative version

Stats

117K views
8.2K downloads
41 bookmarked
Posted

Change File Date Attributes

, 27 Nov 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Change created, modified and accessed time

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)

Share

About the Author

Etienne Rached
Software Developer
Lebanon Lebanon
No Biography provided

You may also be interested in...

Comments and Discussions

 
Questionautomatically changing a filename each time I save a file in visual studio. Pin
Member 1194056227-Aug-15 6:07
memberMember 1194056227-Aug-15 6:07 
GeneralMy vote of 5 Pin
Member 1111263626-Sep-14 8:54
memberMember 1111263626-Sep-14 8:54 
SuggestionThank you (extra code to enumerate a folder) Pin
ztabakov3-Sep-14 16:18
memberztabakov3-Sep-14 16:18 
GeneralMuchas gracias! Pin
Member 1000395021-Apr-13 23:34
memberMember 1000395021-Apr-13 23:34 
GeneralThanks.. works great Pin
saumen_halder3-Apr-13 1:58
membersaumen_halder3-Apr-13 1:58 
QuestionPowershell Option Pin
Member 388509130-Mar-13 20:54
memberMember 388509130-Mar-13 20:54 
GeneralAdding AM or PM to CustomFormat Pin
John Jasper13-Aug-09 12:38
memberJohn Jasper13-Aug-09 12:38 
QuestionHow to change last saved date? Pin
Member 46863649-Jul-09 1:14
memberMember 46863649-Jul-09 1:14 
AnswerRe: How to change last saved date? Pin
Member 388509130-Mar-13 20:48
memberMember 388509130-Mar-13 20:48 
GeneralChanging more than one file's date. Pin
dbett8-Feb-09 17:35
memberdbett8-Feb-09 17:35 
GeneralRe: Changing more than one file's date. Pin
Etienne Rached17-Feb-09 14:55
memberEtienne Rached17-Feb-09 14:55 
Generalexecuting the program Pin
jim sladge6-Jan-09 6:12
memberjim sladge6-Jan-09 6:12 
GeneralRe: executing the program [modified] Pin
Etienne Rached10-Jan-09 16:54
memberEtienne Rached10-Jan-09 16:54 
QuestionConsistency of dates ? Pin
rob tillaart2-Dec-08 23:14
memberrob tillaart2-Dec-08 23:14 
AnswerRe: Consistency of dates ? Pin
Dennis Dykstra5-Dec-08 5:19
memberDennis Dykstra5-Dec-08 5:19 
AnswerRe: Consistency of dates ? Pin
Etienne_CodeProject16-Dec-08 18:52
memberEtienne_CodeProject16-Dec-08 18:52 
GeneralRe: Consistency of dates ? Pin
rob tillaart16-Dec-08 20:44
memberrob tillaart16-Dec-08 20:44 

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

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

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