Reputation: 60691
I am trying to get all the files in an entire directory structure that has been created or modified after a certain date:
for /f "usebackq tokens=1-7* delims=/: " %I in (`dir/tc/o-d/s gstmp\*yell*.tif ^
^| findstr 2010`) do (
if "%K%I%J %N %L%M" GEQ "20100806 PM 0457" (
echo. [ %K-%I-%J %L:%M %N %P. ]
)
)
I got this genius script from Stack Overflow question Batch File: Iterate Over Files Modified Since a Given Date.
I changed gstmp\*yell*.tif
to be just *
, because I want to see all the files.
Unfortunately, it is not working for me.
It echos nothing at all. What am I doing wrongly?
Upvotes: 0
Views: 3504
Reputation: 79983
@ECHO OFF
SETLOCAL
:: Create a dummy directory
MD c:\dummy
XCOPY /L /s /d:04-01-2013 c:\startdir c:\dummy >u:reportfile.txt
:: Way the second
SET "line="
DEL u:\reportfile2.txt 2>nul
FOR /f "delims=" %%i IN (
'XCOPY /L /s /d:04-01-2013 c:\startdir c:\dummy'
) DO CALL :output "%%i"
:: Delete the dummy directory
RD /s /q c:\dummy
GOTO :eof
:output
IF DEFINED line ECHO %line% >>u:reportfile2.txt
SET line=%~1
GOTO :eof
Here are two ways:
The XCOPY
lists all files created/modified after the date specified in mm-dd-yyyy format, because each one would be copied to the dummy empty directory created. The /L only LISTS
the files that would be copied.
The first method adds a line reporting the filecount. The second method suppresses that output. Method 2 has its faults - it's more complicated (obviously) and some strange filenames may be corrupted (this can be overcome if really necessary...). If you're using sensible filenames it'll do the job...
Upvotes: 1