简体   繁体   中英

Getting the file names of all the files that were modified in the last week using batch?

I'm trying to get all the file names of the files that were modified in the last week in a certain directory(has subdirectories). I know that the script below returns the last modified file in each subdirectory. Is it possible to do what I'm trying to do with batch script? If it is possible, what are the changes that should be made to the below script? Thanks in advance :)

@echo off
setlocal EnableDelayedExpansion

for /D %%G in (*) do (
  echo %%G
  cd %%G\

    for /f "delims=" %%F in ('dir /b/a-d/tw') do (
      set last=%%F
    )  

  echo !last!
  cd..
  pause   
)
/D    date          Selects files with a last modified date greater
                    than or equal to (+), or less than or equal to
                    (-), the specified date using the
                    "dd/MM/yyyy" format; or selects files with a
                    last modified date greater than or equal to (+)
                    the current date plus "dd" days, or less than or
                    equal to (-) the current date minus "dd" days. A
                    valid "dd" number of days can be any number in
                    the range of 0 - 32768.
                    "+" is taken as default sign if not specified.

See forfiles /?. There are lots of sample commands.

This works here using Robocopy to provide the list.
The most recent files are shown at the bottom, oldest at the top, for the past 7 days.

Change the folder variable to the tree that you need to check.

@echo off
:: Do NOT remove /L from the robocopy line

    set "folder=d:\data"

for /f "tokens=1,2,*" %%a in ('robocopy "%folder%" "%folder%" *.* /L /s /maxage:7 /nocopy /is /njh /njs /ndl /nc /ns /ts ^|sort ') do echo %%c
pause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM