The "accepted" answer in that link is about using .NET programming libraries to accomplish that for one file. The others were about adding a context menu to update single files. I was looking for a built in command to do it to N files recursively. The answer below worked for doing it for all files. It's not a built-in, but it works. Thanks.
–
jmqFeb 28 '11 at 18:38

It's not a duplicate of Windows version of the Unix touch command either, because this question is asking specifically for recursion. However, note that a few answers to that question have recursive forms.
–
JdeBPFeb 28 '11 at 19:14

7 Answers
7

Use a port of a Unix touch command and simply combine find and touch in the Unix way. There are several choices. Oft-mentioned are GNUWin32, cygwin, and unxutils. Less well known, but in some ways better, are the tools in the SFUA utility toolkit, which run in the Subsystem for UNIX-based Applications that comes right there in the box with Windows 7 Ultimate edition and Windows Server 2008 R2. (For Windows XP, one can download and install Services for UNIX version 3.5.) This toolkit has a large number of command-line TUI tools, from mv and du, through the Korn and C shells, to perl and awk. It comes in both x86-64 and IA64 flavours as well as x86-32. The programs run in Windows' native proper POSIX environment, rather than with emulator DLLs (such as cygwin1.dll) layering things over Win32. And yes, the toolkit has touch and find, as well as some 300 others.All of these toolkits have the well-known disadvantage of running a separate process for every file to be touched, of course. That's not a problem with the following alternatives.

Use one of the many native Win32 touch commands that people have written and published. Many of them support options to perform recursion, without the necessity for a Unix find to wrap around them. (They are, after all, targeting a userbase that is looking for a touch command because it doesn't have a whole load of ported Unix commands.) One such is Stéphane Duguay's touch which as you can see has a --recursive option.

Get clever with the arcane mysteries of CMD. As mentioned in the other answer, COPY /B myfile+,, will update a file's last modification datestamp, using the little-known "plus" syntax of the COPY command (more on which can be found here, incidentally). This of course can be combined with FOR /R to perform the operation recursively, as hinted at in another answer here.

Use a replacement command interpreter and be less clever and more straightforward than CMD.JP Software's TCC/LE is one such. It adds an /S option to its COPY command, meaning that one could use COPY /S with the "plus" syntax to eliminate the need for a FOR wrapper. But that's really still making life unnecessarily difficult for oneself, considering that TCC/LE has a built in TOUCH command that directly supports an /S option.

-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of ';' is encountered. The string '{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find.

-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way that xargs builds its command lines. Only one instance of '{}' is allowed within the command. The command is executed in the starting directory.

Consider a folder c:\myfolder containing 2 files a.txt and b.txt

find . -type f -exec touch {} + is interpreted as :touch a.txt b.txtThis is similar to the way xargs works