@ECHO OFF :: Check Windows version IF NOT "%OS%"=="Windows_NT" GOTO Syntax :: Exactly 3 mandatory command line arguments plus optional /S switch IF "%~3"=="" GOTO Syntax IF NOT "%~4"=="" IF /I NOT "%~4"=="/S" GOTO Syntax :: Check if file or directory exists IF NOT EXIST "%~3" GOTO Syntax :: Check if dates are valid for use with XCOPY's /D switch ECHO.%~1| FINDSTR /R /X /C:"[01]*[0-9][/\-][0-3]*[0-9][/\-][12][0-9][0-9][0-9]" >NUL || GOTO Syntax ECHO.%~2| FINDSTR /R /X /C:"[01]*[0-9][/\-][0-3]*[0-9][/\-][12][0-9][0-9][0-9]" >NUL || GOTO Syntax :: Use a local environment SETLOCAL ENABLEDELAYEDEXPANSION :: Check if file or folder SET Arg3=%~3 SET Type=File ECHO.%~3 | FINDSTR /R /C:"[\?\*]" >NUL IF ERRORLEVEL 1 ( IF "%~nx3"=="" ( SET Type=Folder ) ELSE ( DIR /AD /B "%~dp3" | FINDSTR /R /I /X /C:"%~nx3" >NUL && SET Type=Folder ) IF "%Arg3:~-1,1%"=="\" ( SET Type=Folder SET Arg3=%Arg3:~0,-1% ) IF EXIST "!Arg3!\" SET Type=Folder ) IF /I "%Type%"=="Folder" SET Arg3=%Arg3%\*.* :: List all files after and including TO date in a temporary file XCOPY "%Arg3%" C:\*.* /D:%~2 %4 /H /Y /L | FINDSTR /R /B /V /C:"[1-9][0-9]* " > "%Temp%.\~%~n0.tmp" :: Now list all files older than and including FROM date, and only :: display its path if the file is NOT listed in the temporary file FOR /F "tokens=*" %%A IN ('XCOPY "%Arg3%" C:\*.* /D:%~1 %4 /H /Y /L ^| FINDSTR /R /B /V /C:"[1-9][0-9]* "') DO ( SET Found=0 FOR /F "tokens=*" %%B IN ('TYPE "%Temp%.\~%~n0.tmp"') DO ( IF "%%~A"=="%%~B" SET Found=1 ) IF "!Found!"=="0" ECHO %%A ) :: Delete the temporary file IF EXIST "%Temp%.\~%~n0.tmp" DEL "%Temp%.\~%~n0.tmp" ENDLOCAL GOTO:EOF :Syntax ECHO. ECHO ListFilesBetween.bat, Version 1.02 for Windows NT4+ ECHO List matching files last modified between two dates ECHO. ECHO Usage: LISTFILESBETWEEN from_date to_date file_spec [ /S ] ECHO. ECHO Where: from_date is the earliest timestamp to be included ECHO. to_date is the day after the last timestamp to be included ECHO file_spec is the folder or file specification ECHO /S includes subfolders ECHO. ECHO Notes: Both from_date and to_date must be in MM/DD/YYYY or MM-DD-YYYY format; ECHO the order MM DD YYYY is fixed, the delimiter depends on the locale. ECHO The file_spec must be a fully qualified path, i.e. drive:\path[\files] ECHO or \\server\share\path[\files]; wildcards are allowed. ECHO Files with timestamps equal to from_date are included, files with ECHO timestamps equal to to_date are excluded; to include today's files ECHO without having to calculate tomorrow's date, use a date in the far ECHO future for to_date, e.g. 01/01/2100. ECHO Matching hidden files are included. ECHO Do not use /S switch on the root of the C: drive. ECHO. ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com :: Abort with errorlevel 1 without using EXIT IF "%OS%"=="Windows_NT" COLOR 00