Using batch file to list files created or modified in the last 7days

Viewed 38

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

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.

My knowledge of batch files and their commands is pretty limited. Running Windows 10.

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
1 Answers

If I misunderstood you, you can go deeper into the topic here

forfiles /P FOLDER_PATH\ /S /D -7
Related