Click here to Skip to main content
13,089,386 members (63,250 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


10 bookmarked
Posted 7 Jul 2013

Modifying the Date Attributes of a File

, 6 Aug 2013
Rate this:
Please Sign up or sign in to vote.
Change the accessed, modified, and created date attributes of a file


The File Date Modifier is a simplistic tool that allows the modification of date attributes (modified, accessed, created) for a single file or entire directory. It was developed using C#, WPF and the MVVM design pattern.

How to Use

The Selected Path area allows you to browse to a specific file or choose an entire directory by selecting the Path Type and clicking the Browse button.

Once the path is selected, check which attributes you'll like to modify by clicking its associated check box.

Using the DateTime picker, you are able to select individual sections of the date and time (day, month, year, hour, min, seconds) and increment/decrement its value using the up and down arrow.

Optionally, clicking the big down arrow will bring up a calendar/time picker.

After a Path and at least one Attribute is selected, press the UPDATE button to modify. A message box will appear (with the number of changed files) upon successful write.

Using the Code

Using .NET's System.IO, the file date attributes are able to be modified simply by calling File.SetCreationTime , File.SetLastAccessTime, and File.SetLastWriteTime while passing the file's full path and DateTime as the arguments.  

        /// <summary>
        /// Updates the date attribute information for a file.
        /// </summary>
        /// <param name="file">The file path</param>
        /// <param name="createdTime">The created time.</param>
        /// <param name="accessedTime">The accessed time.</param>
        /// <param name="modifiedTime">The modified time.</param>
        private void updateFileDateInfo(string file, DateTime createdTime, DateTime accessedTime, DateTime modifiedTime)
            if (CreatedChecked)
                File.SetCreationTime(file, createdTime);
            if (AccessedChecked)
                File.SetLastAccessTime(file, accessedTime);
            if (ModifiedChecked)
                File.SetLastWriteTime(file, modifiedTime);

If the Path Type selected is Directory, the selected directory will be searched recursively while updating each file.

/// <summary>
/// Updates the directory date information.
/// </summary>
/// <param name="dir">The directory</param>
private void updateDirDateInfo(string dir)
    foreach (var d in Directory.GetDirectories(dir))
        foreach (var f in Directory.GetFiles(d))
            _fileCountUpdated += 1;
            updateFileDateInfo(f, CreatedDateTime, AccessedDateTime, ModifiedDateTime);

Additional Information

I needed to change specific date attributes of all files in a directory, but only found a few tools that changed individual files (not an entire directory). Since the directory I was working with contained around 100 different files, I decided to write this tool in order to ease the process of updating the date attributes of multiple files at the same time.


  • 2013, Aug. 06 - Update source / tool to support globalization.   
  • 2013, July 07  - Initial publication 


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


About the Author

United States United States
Software Engineer - San Diego, CA

You may also be interested in...

Comments and Discussions

QuestionAwesome! Pin
PMBottas13-Aug-13 15:53
memberPMBottas13-Aug-13 15:53 
AnswerRe: Awesome! Pin
d.moncada13-Aug-13 16:13
memberd.moncada13-Aug-13 16:13 
GeneralMy vote of 5 Pin
fredatcodeproject7-Aug-13 21:39
memberfredatcodeproject7-Aug-13 21:39 
QuestionSuggestion for going from 5 to 5+++ Pin
dandy727-Aug-13 10:52
memberdandy727-Aug-13 10:52 
AnswerRe: Suggestion for going from 5 to 5+++ Pin
d.moncada7-Aug-13 11:03
memberd.moncada7-Aug-13 11:03 
SuggestionFAR Manager Pin
Vitaly Tomilov7-Aug-13 8:57
memberVitaly Tomilov7-Aug-13 8:57 
GeneralRe: FAR Manager Pin
d.moncada7-Aug-13 14:46
memberd.moncada7-Aug-13 14:46 
GeneralRe: FAR Manager Pin
Vitaly Tomilov7-Aug-13 22:45
memberVitaly Tomilov7-Aug-13 22:45 
GeneralRe: My vote of 5 Pin
d.moncada7-Aug-13 4:36
memberd.moncada7-Aug-13 4:36 
GeneralMy vote of 4 Pin
fredatcodeproject6-Aug-13 5:30
memberfredatcodeproject6-Aug-13 5:30 
GeneralRe: My vote of 4 Pin
d.moncada6-Aug-13 5:49
memberd.moncada6-Aug-13 5:49 
GeneralRe: My vote of 4 Pin
fredatcodeproject7-Aug-13 1:28
memberfredatcodeproject7-Aug-13 1:28 
GeneralRe: My vote of 4 Pin
d.moncada7-Aug-13 4:37
memberd.moncada7-Aug-13 4:37 
GeneralRe: My vote of 4 Pin
fredatcodeproject7-Aug-13 21:37
memberfredatcodeproject7-Aug-13 21:37 
Questionvery tasty I wanna eat Pin
Programmer Pavel17-Jul-13 3:05
memberProgrammer Pavel17-Jul-13 3:05 
GeneralMy vote of 5 Pin
newton.saber8-Jul-13 1:57
membernewton.saber8-Jul-13 1:57 
GeneralRe: My vote of 5 Pin
d.moncada9-Jul-13 6:50
memberd.moncada9-Jul-13 6:50 
QuestionAwesome Tool Pin
H.Brydon7-Jul-13 15:41
memberH.Brydon7-Jul-13 15:41 
AnswerRe: Awesome Tool Pin
d.moncada7-Jul-13 17:06
memberd.moncada7-Jul-13 17:06 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 7 Aug 2013
Article Copyright 2013 by d.moncada
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid