Windows recursive touch command
There are several possibilities:
Use a port of a Unix
touch
command and simply combinefind
andtouch
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, frommv
anddu
, through the Korn and C shells, toperl
andawk
. 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 ascygwin1.dll
) layering things over Win32. And yes, the toolkit hastouch
andfind
, 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 Unixfind
to wrap around them. (They are, after all, targeting a userbase that is looking for atouch
command because it doesn't have a whole load of ported Unix commands.) One such is Stéphane Duguay'stouch
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 theCOPY
command (more on which can be found here, incidentally). This of course can be combined withFOR /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 itsCOPY
command, meaning that one could useCOPY /S
with the "plus" syntax to eliminate the need for aFOR
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.
To use only existing Windows functionality (nothing extra to install) try one of these:
forfiles /P C:\Path\To\Root /S /C "cmd /c Copy /B @path+,,"
(recursively "touch" all files starting in the specified path)
OR
forfiles /S /C "cmd /c Copy /B @path+,,"
(recursively "touch" all files starting in current directory)
Since they are readily available, I would recommend taking advantage of the unxutils. They include the find
and touch
commands which will make this very easy.
After changing to the topmost directory you wish to modify:
find . -type f -exec touch {} +
I know this is probably a bit too late but nevertheless, I'll leave my answer just in case someone else needs the same thing.
John T's answer didn't work for me on Windows 7. After some research I found this utility called SKTimeStamp, which does the job perfectly.
Here's an article with more details on how it works: http://www.trickyways.com/2009/08/how-to-change-timestamp-of-a-file-in-windows-file-created-modified-and-accessed/.
Here are the steps you need to perform:
- Install the application
- Go to the directory where you needed to change timestamps
- Search for * in the search box so that the explorer shows all files
- When all the files are found, select them all, right click on them and choose Properties
- In the dialogue choose the TimeStamps tab
- Adjust your dates and times as needed and click on Touch
Voila! All your files have been updated! No need for any unix utils or command lines.
Or you could use the tools already built into Windows, once you already have a "touch" tool of some kind:
for /r %i in (C:\Path\To\Root\*) do @touch "%i"
OR
forfiles /P C:\Path\To\Root /S /C "touch @file"
(N.B.: If you're doing this from a batch file and want to use the for
command, make sure to use double-percent signs for your variables. (e.g. %%i
instead of %i
)