Solved Batch File - List files modified within last 7 days

JDobbsy1987

Hi all, I'm Jamie
Guru
Gold Member
Local time
8:00 AM
Messages
1,861
Location
England, Cheshire
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 My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
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 :thumbsup:

Regards,
JDobbsy1987
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
Back
Top