sleepy
sleepy

Reputation: 193

How do I find last updated files since 1 week?

I have a directory and there are about ~1000 files in there. I want to get the file names which last updated since 7 days? And write this file names to another file. I'm using windows 2012 and I want to do that with batch script. How may I do that?

UPDATE: I tried

@echo off
setlocal enableextensions disabledelayedexpansion
set "folder=c:\some\where"
(  for /f "tokens=*" %%a in ('
      robocopy "%folder%" "%folder%" * /l /nocopy /is /maxage:7 /njh /njs /nc /ns /ndl 
   ') do echo(%%a
) > outputFile.txt

However, I receive this error:

ERROR : No Destination Directory Specified.
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir  (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.
For more usage information run ROBOCOPY /?

**** /MIR can DELETE files as well as copy them !

Upvotes: 0

Views: 219

Answers (1)

MC ND
MC ND

Reputation: 70923

@echo off
    setlocal enableextensions disabledelayedexpansion
    set "folder=c:\some\where"
    (  for /f "tokens=*" %%a in ('
          robocopy "%folder%" "%folder%" * /l /nocopy /is /maxage:7 /njh /njs /nc /ns /ndl 
       ') do echo(%%a
    ) > outputFile.txt

This uses robocopy command to retrieve the list of the required files. It will only list /l, without copying anything /nocopy, all the files, including those considered the same file /is, with a max age of 7 days /maxage:7, without headers /njh, summary /njs, file class /nc, size /ns or directory listing /ndl.

The output of the command will include some blank columns that are removed with the for loop.

Upvotes: 2

Related Questions