Batch File - List files modified within last 7 days


  1. Posts : 2,177
    Windows 8.1 Pro x64
       #1

    Batch File - List files modified within last 7 days


    Hi All,

    I'm trying to create a batch file that will create a text file listing all the files within a folder that has been modified within the last 7 days, i thought this was going to be easy using some kind of switch that looks at the modified date but that doesn't seem to exist and i can't figure a way of doing it.

    i have this script that will list files older than 7 days:
    Code:
    forfiles -p c:\ /s /m *.* /d -7 /c "cmd /c echo @file > c:\users\jdobbsy1987\desktop\list.txt"
    and this cmd that will list all my files in in date order (newest first):
    Code:
    dir /s /o:-d
    But can't seem to get anything to list files modified within the last 7 days.
    It would need to look in subdirectories too.

    Any help would be greatly appreciated.

    Regards,
    JDobbsy1987
      My Computer


  2. Posts : 2,177
    Windows 8.1 Pro x64
    Thread Starter
       #2

    Just wanted to let you know i have now managed to get this sorted although it was with a powershell script as opposed to a batch script.

    This is the script i have used:
    Code:
    dir "c:\users\jdobbsy1987\" | ? {$_.PSIsContainer} | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-7)} | ConvertTo-Html Name | Set-Content \\server\share\New_Media.htm
    Although this code is slightly different than i originally wanted as this converts the output to a htm file rather than a text file but if you did want to output to a text file then this would be the script:
    Code:
    dir "c:\users\jdobbsy1987\" | ? {$_.PSIsContainer} | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-7)} | out-file \\server\share\New_Media.txt -width 150
    Hope this helps others looking for the same thing

    Regards,
    JDobbsy1987
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 23:53.
Find Us