Click here to Skip to main content
15,392,679 members
Articles / Programming Languages / C++
Posted 26 Nov 2002


70 bookmarked

Touch for Windows

Rate me:
Please Sign up or sign in to vote.
4.43/5 (51 votes)
17 Mar 2010BSD2 min read
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.

Comments and Discussions

QuestionDoes not compile on Windows 10 VS 2013 Pin
Garry Lowther30-Nov-16 4:16
MemberGarry Lowther30-Nov-16 4:16 
GeneralMy vote of 5 Pin
Member 109276896-Jul-14 6:44
MemberMember 109276896-Jul-14 6:44 
QuestionEXIF enhancement Pin
YitzY Berlin16-Mar-13 23:25
MemberYitzY Berlin16-Mar-13 23:25 
GeneralMy vote of 4 Pin
Aravind Kumar K22-Aug-12 6:44
MemberAravind Kumar K22-Aug-12 6:44 
QuestionGreat utility - minor feature request Pin
ncdev10-Feb-12 7:44
Memberncdev10-Feb-12 7:44 
QuestionChange "Date Taken" information (EXIF) for photos? Pin
beerslayer20008-Dec-11 12:13
Memberbeerslayer20008-Dec-11 12:13 
GeneralThe licence Pin
Rozis16-Mar-10 11:22
MemberRozis16-Mar-10 11:22 
GeneralRe: The licence Pin
Jörgen Sigvardsson17-Mar-10 2:15
MemberJörgen Sigvardsson17-Mar-10 2:15 
Generaltouch doesn't create a new file Pin
francwalter13-Mar-10 14:58
Memberfrancwalter13-Mar-10 14:58 
GeneralRe: touch doesn't create a new file Pin
Jörgen Sigvardsson13-Mar-10 21:30
MemberJörgen Sigvardsson13-Mar-10 21:30 
GeneralRe: touch doesn't create a new file Pin
Mart Smeets15-Mar-10 13:00
MemberMart Smeets15-Mar-10 13:00 
GeneralRe: touch doesn't create a new file Pin
Jörgen Sigvardsson15-Mar-10 21:54
MemberJörgen Sigvardsson15-Mar-10 21:54 
GeneralRe: touch doesn't create a new file Pin
Jörgen Sigvardsson15-Mar-10 22:28
MemberJörgen Sigvardsson15-Mar-10 22:28 
GeneralRe: touch doesn't create a new file Pin
Mart Smeets16-Mar-10 7:34
MemberMart Smeets16-Mar-10 7:34 
GeneralRe: touch doesn't create a new file Pin
Jörgen Sigvardsson16-Mar-10 20:41
MemberJörgen Sigvardsson16-Mar-10 20:41 
GeneralRe: touch doesn't create a new file [modified] Pin
Mart Smeets17-Mar-10 11:48
MemberMart Smeets17-Mar-10 11:48 
GeneralRe: touch doesn't create a new file Pin
Jörgen Sigvardsson15-Mar-10 22:01
MemberJörgen Sigvardsson15-Mar-10 22:01 
GeneralShell integration [modified] Pin
CBoland31-Jan-07 12:52
MemberCBoland31-Jan-07 12:52 
GeneralRe: Shell integration Pin
Jörgen Sigvardsson31-Jan-07 22:33
MemberJörgen Sigvardsson31-Jan-07 22:33 
GeneralRe: Shell integration Pin
SteveKing17-Mar-10 21:09
MemberSteveKing17-Mar-10 21:09 
GeneralRe: Shell integration Pin
Astyan28-Feb-11 18:36
MemberAstyan28-Feb-11 18:36 
GeneralWell Done - it just works !! Pin
ChrisRRRR31-Jan-07 0:59
MemberChrisRRRR31-Jan-07 0:59 
GeneralRe: Well Done - it just works !! Pin
Jörgen Sigvardsson31-Jan-07 22:32
MemberJörgen Sigvardsson31-Jan-07 22:32 
GeneralRecursion Pin
Bleary Eye28-Nov-06 5:54
MemberBleary Eye28-Nov-06 5:54 
GeneralDoes not create files if it does not exist. Pin
gorfou7-Sep-06 7:22
Membergorfou7-Sep-06 7:22 

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.