Click here to Skip to main content
13,353,706 members (57,137 online)
Click here to Skip to main content
Add your own
alternative version


69 bookmarked
Posted 26 Nov 2002

Touch for Windows

, 17 Mar 2010
Rate this:
Please Sign up or sign in to vote.
This is the touch tool ported to Windows


I've seen at least two people asking for a Windows version of the UNIX utility touch this past week. So here it is: a Windows version of the OpenBSD touch command. It's not fully compatible as my utility can only touch one file at a time and does not support the -f argument (force touch, ignoring access rights). However, my version supports altering modification, access and creation time, while the OpenBSD version only supports alteration of access and modification time.

If you have a need for a touch utility which ignores access rights and can handle multiple files (including globing), tell me and I'll see what I can do.

I've also made sure it's UNICODE compatible, but as my system is as western as it gets, I haven't really been able to test it. If you find anything fishy when compiled as a UNICODE binary, please let me know.

What Does It Do?

For those who don't know, here's a simple explanation: It updates the dates associated with a file to whatever you want it to be. It can change access, modification and creation dates. You as a user can update them independently of each other, you can update them with any possible date. Dates can be now, user specified or copied from another file. If you try to touch a file which does not exist, this command will create it for you (empty of course).

You can always run touch -h for help.

Where's the Article?

This is not rocket science. I'm basically just using simple Win32 API functions. Writing an article about it would be like reciting the MSDN documentation. If you are interested in how it works, use the source - it's not big and it doesn't really contain any surprises.

License Grant

You are granted a license to use the code for whatever purpose, if and only if the following conditions are met:

  • You may expect no warranties from my part. If you break something, you fix it.
  • If we meet some day in the flesh, you may buy me a beer of my choice. This is not a requirement, but it would be a very nice thing to do and I would appreciate it. If your religion prohibits you from buying any alcohol, even if not for yourself, a coke is fine or whatever well testing beverage which you find morally and ethically acceptable.

Revision history

  • 2002-11-28 - Initial version
  • 2004-04-03 - Bug fixes: UNICODE, argument parsing, daylight saving, time string parsing
  • 2006-02-15 - Wildcard support, much thanks to PhaetonTheGreat!
  • 2010-03-16 - Wildcard support introduced a bug. Fixed it, and gave touch the ability to handle multiple files and glob patterns
  • 2010-03-17 - Added support for directories per request. See the new -d switch. -r can also be specified to use a directory as a time source


This article, along with any associated source code and files, is licensed under The BSD License


About the Author

Jörgen Sigvardsson
Software Developer (Senior)
Sweden Sweden
I make software.

You may also be interested in...

Comments and Discussions

GeneralGood, but look at .... Pin
amauta2-Feb-05 12:43
memberamauta2-Feb-05 12:43 
GeneralRe: Good, but look at .... Pin
gorfou7-Sep-06 8:19
membergorfou7-Sep-06 8:19 
GeneralI was looking for a good touch :) Pin
Avinoam Sapir19-Jan-05 22:28
memberAvinoam Sapir19-Jan-05 22:28 
Generalquestion Pin
zetroooooo3-Sep-04 20:44
memberzetroooooo3-Sep-04 20:44 
GeneralRe: question Pin
Jörgen Sigvardsson3-Sep-04 23:53
memberJörgen Sigvardsson3-Sep-04 23:53 
QuestionDirectory Support? Pin
Adam P.30-May-04 12:33
sussAdam P.30-May-04 12:33 
AnswerRe: Directory Support? Pin
DavidLowndes@msn20-Feb-06 23:37
memberDavidLowndes@msn20-Feb-06 23:37 
AnswerRe: Directory Support? Pin
Willow530-May-09 18:45
memberWillow530-May-09 18:45 
Hmm, TouchPro seems like a step in the wrong direction. It's a Windows GUI app that registers itself into Windows Explorer -- hardly a lightweight W32 app like Jörgen's demo. TouchPro includes a command line version but jddesign forces you to register with them before you can use it.

Why don't you use gnu or cygwin Win32 touch.exe for directory touch functionality? Sources for both are freely available.

Alternatively, Jörgen might be persuaded to update his demo for this OpenBSD-like functionality. Hint, hint Jörgen!

Hi hi
GeneralProblems with Seconds Pin
mario543233-Apr-04 5:10
membermario543233-Apr-04 5:10 
GeneralRe: Problems with Seconds Pin
Jörgen Sigvardsson3-Apr-04 7:06
memberJörgen Sigvardsson3-Apr-04 7:06 
GeneralRe: Problems with Seconds Pin
Jörgen Sigvardsson3-Apr-04 8:03
memberJörgen Sigvardsson3-Apr-04 8:03 
GeneralFew small FYIs Pin
Joe Woodbury15-Mar-04 8:26
memberJoe Woodbury15-Mar-04 8:26 
GeneralRe: Few small FYIs Pin
Jörgen Sigvardsson16-Mar-04 0:41
memberJörgen Sigvardsson16-Mar-04 0:41 
GeneralRe: Few small FYIs Pin
Jörgen Sigvardsson3-Apr-04 8:04
memberJörgen Sigvardsson3-Apr-04 8:04 
GeneralRe: Few small FYIs Pin
Nemanja Trifunovic13-Apr-04 11:10
memberNemanja Trifunovic13-Apr-04 11:10 
GeneralRe: Few small FYIs Pin
Jörgen Sigvardsson3-Apr-04 8:13
memberJörgen Sigvardsson3-Apr-04 8:13 
Generalmultiple files Pin
JMWillson16-Sep-03 14:45
memberJMWillson16-Sep-03 14:45 
GeneralRe: multiple files Pin
Jörgen Sigvardsson16-Sep-03 21:15
memberJörgen Sigvardsson16-Sep-03 21:15 
Generalproblem Pin
sunil_g720-Jul-03 23:48
membersunil_g720-Jul-03 23:48 
GeneralRe: problem Pin
Jörgen Sigvardsson20-Jul-03 23:51
memberJörgen Sigvardsson20-Jul-03 23:51 
GeneralRe: problem Pin
Alan M. Taren24-Jul-03 9:38
memberAlan M. Taren24-Jul-03 9:38 
GeneralRe: problem Pin
Jörgen Sigvardsson24-Jul-03 9:41
memberJörgen Sigvardsson24-Jul-03 9:41 
GeneralRe: problem Pin
Anonymous2-Aug-05 2:33
sussAnonymous2-Aug-05 2:33 
QuestionRe: problem Pin
DavidCrow21-Feb-06 3:54
memberDavidCrow21-Feb-06 3:54 
AnswerRe: problem Pin
Jörgen Sigvardsson21-Feb-06 5:01
memberJörgen Sigvardsson21-Feb-06 5:01 

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
Web01 | 2.8.180111.1 | Last Updated 17 Mar 2010
Article Copyright 2002 by Jörgen Sigvardsson
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid