问题描述
使用下面的代码,我们可以列出两个日期之间的文件.但是我们还需要检查时间戳.即列出日期&之间的所有文件;时间.
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
推荐答案
另一种更简单(更快!)的方法是:
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
是的,我知道此方法不包括秒数,并且取决于语言环境,但是对于OP和一定数量的用户来说可能就足够了.只需将 %% c %% a %% b
顺序更改为适当的顺序即可解决语言环境问题(例如 %% c %% b %% a
),并且可能需要对"tokens = 1-7 *
部分进行少量调整.
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.
这篇关于两个时间戳之间的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!