List of files between two timestamps

我们两清 提交于 2021-02-08 03:58:35

问题


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

回答1:


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"



回答2:


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 year
  • MM = two digit month
  • DD = two digit day of month
  • hh = two digit hours in 24 hour format
  • mm = two digit minutes
  • ss = 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 minutes

When 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.




回答3:


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.



来源:https://stackoverflow.com/questions/29742739/list-of-files-between-two-timestamps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!