Click here to Skip to main content
13,047,285 members (57,358 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 11 Jul 2005

WinTouch - Change access date, creation date and modified date for files and directories

, 11 Jul 2005
Rate this:
Please Sign up or sign in to vote.
Touches a file with specified date/time so that its access, creation or modified date is changed.

Sample Image - WinTouch.gif


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
wintouch -a -m -c -t "5/5/2003 2:2:2AM" -d subdir

Code Walkthrough

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];
    switch (s.ToLower())
        case "-s":
            winTouch.recurseSubDirs = true;
        case "-a":
            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;
        if (this.changeAccessDate)
            File.SetLastAccessTime(path, this.touchTime);
        if (this.changeModifiedDate)
            File.SetLastWriteTime(path, this.touchTime);
    if (this.changeCreatedDate)
        File.SetCreationTime(path, this.touchTime);

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 TouchFilesInDir.

if (this.recurseSubDirs)
    string[] allDirs = Directory.GetDirectories(dir);
    foreach(string oneDir in allDirs)
        this.TouchFilesInDir(oneDir, filePattern);


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

France France

You may also be interested in...

Comments and Discussions

GeneralMany Thanks Pin
JaECH3-Oct-07 6:21
memberJaECH3-Oct-07 6:21 
GeneralGimme some sunglasses Pin
dogby13-Aug-07 15:48
memberdogby13-Aug-07 15:48 
GeneralTime Difference Pin
Abc Dimension28-May-07 23:21
memberAbc Dimension28-May-07 23:21 
QuestionRead only files? Pin
DuneAgent31-Jul-06 22:33
memberDuneAgent31-Jul-06 22:33 
GeneralCreation Date Pin
Jamsey1200125-Jul-06 2:26
memberJamsey1200125-Jul-06 2:26 
GeneralNice Pin
Michael P Butler11-Jul-05 8:46
memberMichael P Butler11-Jul-05 8:46 
GeneralI hate to be terribly negative BUT ..... Pin
fwsouthern11-Jul-05 8:01
memberfwsouthern11-Jul-05 8:01 
GeneralRe: I hate to be terribly negative BUT ..... Pin
SathishVJ11-Jul-05 22:59
memberSathishVJ11-Jul-05 22:59 
GeneralRe: I hate to be terribly negative BUT ..... Pin
fwsouthern12-Jul-05 6:09
memberfwsouthern12-Jul-05 6:09 

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
Web02 | 2.8.170713.1 | Last Updated 11 Jul 2005
Article Copyright 2005 by SathishVJ
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid