Reputation: 21
using the below code we are able to list the files between two dates. But we need to check the timestamp also. i.e. List all the files between date & time.
wmic datafile where "drive='%drive%' and path='%folder:\=\\%' and creationdate>'%start%' and creationdate<'%end%'" get creationdate, name, size
Upvotes: 2
Views: 603
Reputation: 67216
Another much simpler (and faster!) approach would be this one:
EDIT: I modified the former code so it now process creation dates, instead of last modified ones.
@echo off
setlocal EnableDelayedExpansion
if "%~2" neq "" goto begin
echo Usage: %0 YYYYMMDDHHMMstart YYYYMMDDHHMMend
goto :EOF
:begin
for /F "skip=5 tokens=1-7* delims=/: " %%a in ('dir /A-D /T:C *.*') do (
if "%%h" equ "" goto break
set "hour=%%d"
if "%%f" equ "p.m." set /A "hour=(1%%d+12)%%100"
set "fileDate=%%c%%a%%b!hour!%%e"
if "!fileDate!" geq "%~1" if "!fileDate!" leq "%~2" echo %%a/%%b/%%c %%d:%%e %%f %%g %%h
)
:break
Yes, I know that this method don't include the seconds and it is locale dependant, but it may be enough for the OP and a certain number of users. The locale problem may be fixed with a simple change in the %%c%%a%%b
order to the appropriate one (like %%c%%b%%a
) and perhaps a small adjustment in the "tokens=1-7*
part.
Upvotes: 1
Reputation: 130829
Working with timestamps in WMI queries is a pain. You must either specify a date in the format 'YYYYMMDD'
, or date and time in the format 'YYYYMMDDhhmmss.ffffffSZZZ'
Where
YYYY
= full four digit yearMM
= two digit monthDD
= two digit day of monthhh
= two digit hours in 24 hour formatmm
= two digit minutesss
= two digit seconds.ffffff
= six digit fractional seconds (microseconds)SZZZ
= time zone expressed as minutes offset from UTC time
S
= time zone sign, either +
, or -
ZZZ
= three digit minutesWhen expressing a date, the string must be exactly 6 characters long.
For example, January 15, 2015 is expressed as '20150115'
.
When expressing a date-time, the string must be exactly 25 characters long.
For example, January 15, 2015, 3:14 PM Eastern Standard Time is expressed as '20150115151400.000000-300'
.
So your existing query does not have to change. You just need to make sure your %start%
and %end%
strings are properly formatted date-time values.
Upvotes: 1
Reputation: 57252
Check FileTimeFilterJS.bat To print files between two dates in the current directory try with in :
call FileTimeFilterJS "." -beginDate "September 1, 2014 10:15 AM" -endDate "November 1, 2014 10:15 PM"
Upvotes: 1