简体   繁体   English

使用批处理文件列出过去 7 天内创建或修改的文件

[英]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

If I misunderstood you, you can go deeper into the topic here如果我误解了你,你可以 go 在这里深入探讨

forfiles /P FOLDER_PATH\ /S /D -7

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批处理文件,以在过去几天创建或修改的所有.docx文件上设置attrib + r - batch file to set attrib +r on all .docx files created or modified in the last days 批处理文件-复制两个最后修改的文件 - Batch file - copy two last modified files Windows批处理:将名称,路径,修改的数据,创建日期和所有者的所有文件列出到csv文件或txt文件中 - Windows Batch : list all files with name, path, data modified, date created and owner into a csv file or txt file 如果批处理文件修改日期早于90天,请删除文件 - If Batch File Modified Date is older than 90 days, delete files 如何使用批处理文件获取今天在文件夹中创建/修改的文件数 - How to get count of files created/modified today in a folder using batch file 获取使用批处理在上周修改的所有文件的文件名? - Getting the file names of all the files that were modified in the last week using batch? 如何使用批处理文件修改所有文件和子目录的时间戳(最近修改) - How can I can modify, using a batch file, the time stamp (last modified) of all files and subdirectories 如何使用批处理文件获取目录中多个文件的最后修改日期 - How to get last modified date for multiple files in a directory using a Batch file 如何在批处理文件中回显文件的最后修改时间? - How can I echo a files last modified time in a batch file? 使用批处理从文件夹中复制过去 2 小时修改过的文件 - copy last 2 hours modified files from the folder using batch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM