0

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   
)
sope
  • 86
  • 2
  • 9
  • Did you do at least a basic search here first for previous questions? Try searching for `[batch-file] find modified files` (including the square brackets), and see what you might be able to find. – Ken White May 02 '14 at 13:43
  • @ken Yah I did.. I just don't know how to get the files that were modified in the **last week**. – sope May 02 '14 at 13:57
  • There are several in those search results that mention getting the modified date (oldest files, files in last month, newest files). I think a little effort might make one of those work for you. (We try hard to not duplicate questions here.) – Ken White May 02 '14 at 14:10
  • [Here's a question](http://stackoverflow.com/q/6840156) about checking the time stamp and deleting files older than 2 days. It should give you a start (change 2 days to 7, change del to dir /s). – Ken White May 02 '14 at 14:20
  • http://stackoverflow.com/questions/7758987/select-files-between-two-dates - remains how to know when`"last week" started and ended. – Stephan May 02 '14 at 14:21
  • Thanks! hints and guides are always better than a complete answer!! – sope May 02 '14 at 14:29
  • FORFILES /D option can make your life easy! Especially if you have a method to compute the date 7 days ago. I like to use my [getTimestamp.bat](http://www.dostips.com/forum/viewtopic.php?f=3&t=4847) to do date computations. – dbenham May 02 '14 at 15:03

2 Answers2

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

trigger
  • 76
  • 1
0

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
foxidrive
  • 40,353
  • 10
  • 53
  • 68