Introduction
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.
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.
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);
}
updateDirDateInfo(d);
}
}
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.
History
- 2013, Aug. 06 - Update source / tool to support globalization.
- 2013, July 07 - Initial publication