![]() |
Desktop Development »
Files and Folders »
Files
Beginner
License: The Code Project Open License (CPOL)
Change File Date AttributesBy Etienne RachedChange created, modified and accessed time |
C#, Windows, .NET, Visual Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
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:
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);
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).
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
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 Web15 | Advertise on the Code Project |