Monday, July 1, 2013

One Line Windows Touch Command (Windows 7, Windows 8, etc.)

I was looking around the web for an easy way to simulate the unix command touch - but I kept finding old variants that would not work past Windows ME. I worked with the FOR loop in batch scripting. Here's the version that works for me:

To set all CSV files to the current time:

for /F "usebackq delims=|"  %i in (`dir /B *.csv`) do copy %i /B+ ,,/Y

Note: to set a single file to the current date:

copy filenamt /B+ ,,/Y

A lot of sites suggested dir with no /B - but this doesn't work for me in Windows 8.

Of course, you can "touch" all files like so:

for /F "usebackq delims=|"  %i in (`dir /B *.*`) do copy %i /B+ ,,/Y

No comments: