This tool is similar to the touch utility in UNIX. I wrote this tool while I was experimenting with some time based files and I needed to change the creation date of files to a past or previous date.
.NET 1.1 is required for using this tool. The usage can be obtained by typing "wintouch /?" on the command line.
wintouch -p *.txt -s -t "5/5/2005 4:14:15AM" -a -c -m
wintouch -a -m -c -t "5/5/2003 2:2:2AM" -d subdir
First, we walk through the different input parameters and set appropriate local variables.
static void Main(string args)
WinTouch winTouch = new WinTouch();
for(int i=0; i<args.Length; i++)
string s = args[i];
winTouch.recurseSubDirs = true;
winTouch.changeAccessDate = true;
The core of this small program is the method
TouchFilesInDir which accepts as parameters the directory within which files have to be 'touched' and the file name pattern.
For each file in the directory that matches the pattern, we change the access time, modified time or creation time as requested.
string files = Directory.GetFiles(dir, filePattern);
foreach(string oneFile in files)
string path = oneFile;
We then do the same for the list of directories also. If the user has chosen to recurse through sub directories, then we recursively call
string allDirs = Directory.GetDirectories(dir);
foreach(string oneDir in allDirs)