How to search for files that were modified today in Windows.
October 26, 2009
Windows has a “find” command, but it’s nothing like the Unix command “find” and is pretty useless. DIR can do recursive searches (using /s/b options), and is pretty useful, but there’s no way to get it to search based on dates – just file names.
But what if you want to know, for example, which log files have been modified today? Turns out, XCOPY can do this. It can copy files based on modification date, and the /L option tells it to just print the names of the files it would copy, but not actually copy them. Here’s the command to find all .log files on the C: drive that were modified on or after October 26, 2009:
xcopy /s /d:10-26-2009 /i /l /y c:\*.log \temp
Update:
Of course, you don’t want to manually specify the date every time. You could use the %DATE% cmd variable, but the output is wrong:
C:\temp>echo %DATE%
Wed 10/28/2009
The solution is to pick apart the string returns by %DATE% and munge it back together in the desired format:
C:\temp>echo %DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
10-28-2009
So, the command to find all tomcat logs that have changed today becomes:
xcopy /s /d:%DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4% /i /l /y c:\tomcat5.5\*.log \temp