Click here to Skip to main content
5,787,682 members and growing! (18,340 online)
Email Password   helpLost your password?
Desktop Development » Files and Folders » Files     Beginner License: The Code Project Open License (CPOL)

Change File Date Attributes

By Etienne Rached

Change created, modified and accessed time
C#, Windows, .NET, Visual Studio, Dev

Posted: 27 Nov 2008
Updated: 27 Nov 2008
Views: 3,369
Bookmarked: 11 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 3.03 Rating: 3.90 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 16.7%
3
4 votes, 66.7%
4
1 vote, 16.7%
5

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



Occupation: Web Developer
Location: Lebanon Lebanon

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
Generalexecuting the programmemberjim sladge6:12 6 Jan '09  
QuestionConsistency of dates ?memberrob tillaart23:14 2 Dec '08  
AnswerRe: Consistency of dates ?memberDennis Dykstra5:19 5 Dec '08  
AnswerRe: Consistency of dates ?memberEtienne_CodeProject18:52 16 Dec '08  
GeneralRe: Consistency of dates ?memberrob tillaart20:44 16 Dec '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Nov 2008
Editor: Deeksha Shenoy
Copyright 2008 by Etienne Rached
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project