[英]Using batch file to list files created or modified in the last 7days
I'm trying to create a batch file that will look across a folder and its subfolders and list any file that has been created or modified within say the last 7 days.我正在尝试创建一个批处理文件,该文件将查看文件夹及其子文件夹并列出过去 7 天内创建或修改的所有文件。 I only want to know files that meet the condition, not folders.
我只想知道符合条件的文件,而不是文件夹。
I've played around with DIR command, but whatever I do, it always seems to list everything.我玩过 DIR 命令,但无论我做什么,它似乎总是列出所有内容。
I found this piece of code in Stackoverflow from 2017 which looked promising (I played around with the DIR switches), but it doesn't seem to create any output.我在 2017 年的 Stackoverflow 中发现了这段代码,看起来很有希望(我玩过 DIR 开关),但它似乎没有创建任何 output。
My knowledge of batch files and their commands is pretty limited.我对批处理文件及其命令的了解非常有限。 Running Windows 10.
运行 Windows 10。
TIA TIA
Nigel奈杰尔
@echo off
setlocal EnableDelayedExpansion
echo Input the date(dd/mm/yyyy):
set /p compDate=
for /F "tokens=1-3 delims=/" %%a in ("%compDate%") do set compDate=%%c%%b%%a
echo Input the directory:
set /p directory=
SET Exit=%UserProfile%\Desktop\test.txt
pushd "%directory%"
(for /F "tokens=1-5*" %%a in ('dir /s /od /tc /a-d') do (
set "fileDate=%%a"
if "!fileDate:~2,1!!fileDate:~5,1!" equ "//" (
for /F "tokens=1-3 delims=/" %%x in ("!fileDate!") do set fileDate=%%z%%y%%x
if !fileDate! geq %compDate% (
set "fileSize= %%e"
echo %%a %%b %%c %%d !fileSize:~-16! %%f
)
)
)) > %Exit%
popd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.