S h o r t S t o r i e s

// Tales from software development

How to 'touch' files with the COPY command

leave a comment »

MSBuild has a Touch task to update the date/time stamp on a file like the UNIX touch command.

A little while ago I needed a way to touch a file but I didn’t want to use MSBuild and I didn’t really want to download a third-party touch utility. I wondered if there was a way to do it using just the commands supplied with Windows. It turns out there is…

This isn’t very intuitive but the COPY command can be used like this:

copy /b filename.ext + ,,

to update a file’s date/time stamp.

It works because the arguments instruct the copy command to update the specified file by appending a file but the file is not specified. So the file is, in effect, copied to itself. In reality, all that the COPY command does is update the last modified date/time stamp.

There’s an old Microsoft KnowledgeBase article that explains this in more detail here:



Written by Sea Monkey

December 2, 2008 at 9:53 pm

Posted in Development

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: