Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need help with a batch file/script
New Posts  All Forums:Forum Nav:

Need help with a batch file/script

post #1 of 6
Thread Starter 
Hello everyone! I'm in need of some assistance with a batch file/script. I have a network share that I need to delete the contents of every three days, but I also need to keep three days worth of data in that folder. So I basically need a batch file that will delete all contents of the folder that are older than three days. I have a script that can delete the contents of the folder, but I can't figure out how to keep three days worth of data. Any help would be greatly appreciated! Below is what I have so far.

REM "This will delete all files in the Radiology folder. It will even delete read-only files"

echo off

del /F /Q "E:\Files\Groups\SoarianDowntimeReports\Radiology\*.*"
post #2 of 6
I believe you can just use a time modifier on there to check the date and use >3 days old.
Let me see if I can find the code real quick.

Edit: Go to the post by e.James
Edited by atminside - 3/11/14 at 8:53am
H2O^3
(25 items)
 
Server
(10 items)
 
 
CPUMotherboardGraphicsRAM
2600k p8z77-v lk 780 classified hydro copper g.skill sniper 
Hard DriveCoolingOSMonitor
Samsung 840 EVO Swiftech Apogee HD Windows 7 Professional 64-bit Dell U2414H 
MonitorMonitorMonitorKeyboard
Dell U2414H Dell U2414H LG 23" 1080p LED g710+ 
PowerCaseMouseAudio
OCZ ZT 750W Corsair Air 540 White G700 G930 
AudioOtherOtherOther
Z313 Swiftech MCP35X ST30 240mm GT-S 360mm 
OtherOtherOtherOther
EasyMountLCD 3+1 Pyramid Monitor Mount Fanatec CSR Wheel Fanatec CSR Elite Pedals Fanatec ClubSport Shifter SQ 
Other
Microsoft Xbox 360 Wired Controller 
CPUMotherboardGraphicsRAM
FX-6300 GA-970A-UD3 HD5450 Fanless Samsung 16GB ECC 1333MHz 
Hard DriveHard DriveCoolingOS
Western Digital Blue 250GB Western Digital Red 2TB Xigmatek Loki Windows Server 2012 
PowerCase
Rosewill Green 430W NZXT M59 
  hide details  
Reply
H2O^3
(25 items)
 
Server
(10 items)
 
 
CPUMotherboardGraphicsRAM
2600k p8z77-v lk 780 classified hydro copper g.skill sniper 
Hard DriveCoolingOSMonitor
Samsung 840 EVO Swiftech Apogee HD Windows 7 Professional 64-bit Dell U2414H 
MonitorMonitorMonitorKeyboard
Dell U2414H Dell U2414H LG 23" 1080p LED g710+ 
PowerCaseMouseAudio
OCZ ZT 750W Corsair Air 540 White G700 G930 
AudioOtherOtherOther
Z313 Swiftech MCP35X ST30 240mm GT-S 360mm 
OtherOtherOtherOther
EasyMountLCD 3+1 Pyramid Monitor Mount Fanatec CSR Wheel Fanatec CSR Elite Pedals Fanatec ClubSport Shifter SQ 
Other
Microsoft Xbox 360 Wired Controller 
CPUMotherboardGraphicsRAM
FX-6300 GA-970A-UD3 HD5450 Fanless Samsung 16GB ECC 1333MHz 
Hard DriveHard DriveCoolingOS
Western Digital Blue 250GB Western Digital Red 2TB Xigmatek Loki Windows Server 2012 
PowerCase
Rosewill Green 430W NZXT M59 
  hide details  
Reply
post #3 of 6
Just curious, are you going to need to delete subfolders too? Because you will have to add to that solution if so.

EDIT: Decided to just add it in anyway. tongue.gif If you don't need to do subfolders just delete the third line.
Code:
cd /D E:\Files\Groups\SoarianDowntimeReports\Radiology\
forfiles /S /M *.* /D -3 /C "cmd /c del @path"
forfiles /S /D -3 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"

Edited by Tnt6200 - 3/11/14 at 4:55pm
The Clunker
(11 items)
 
Lenovo Y40
(6 items)
 
 
CPUMotherboardGraphicsRAM
Core 2 Quad Q8400 Asus P5P43TD Powercolor 7950 4GB Patriot Viper 
Hard DriveHard DriveCoolingOS
80GB WD Caviar Blue 500GB WD Caviar Black Coolermaster Hyper TX Windows 7 Home Premium 64-bit 
MonitorPowerCase
20" Samsung Corsair CX600M Antec 300 
CPUGraphicsRAMHard Drive
i7-4510U R9 M275 2GB 8GB @ 1600MHz 500+8GB 5400rpm SSHD 
OSMonitor
Windows 8.1 14" 1080p 
  hide details  
Reply
The Clunker
(11 items)
 
Lenovo Y40
(6 items)
 
 
CPUMotherboardGraphicsRAM
Core 2 Quad Q8400 Asus P5P43TD Powercolor 7950 4GB Patriot Viper 
Hard DriveHard DriveCoolingOS
80GB WD Caviar Blue 500GB WD Caviar Black Coolermaster Hyper TX Windows 7 Home Premium 64-bit 
MonitorPowerCase
20" Samsung Corsair CX600M Antec 300 
CPUGraphicsRAMHard Drive
i7-4510U R9 M275 2GB 8GB @ 1600MHz 500+8GB 5400rpm SSHD 
OSMonitor
Windows 8.1 14" 1080p 
  hide details  
Reply
post #4 of 6
Thread Starter 
Quote:
Originally Posted by Tnt6200 View Post

Just curious, are you going to need to delete subfolders too? Because you will have to add to that solution if so.

EDIT: Decided to just add it in anyway. tongue.gif If you don't need to do subfolders just delete the third line.
Code:
cd /D E:\Files\Groups\SoarianDowntimeReports\Radiology\
forfiles /S /M *.* /D -3 /C "cmd /c del @path"
forfiles /S /D -3 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"


There are no subfolders in the folder. I just need to make sure three days of contents always stay in that folder, and that the batch file can delete files older than three days. Does your script above accomplish this?
post #5 of 6
Yes it does. The -3 means the last modified date must be 3 less than or equal to the current date. (i.e. 3 days old)

This will do the same thing, but it's a bit smaller:
Code:
forfiles /P E:\Files\Groups\SoarianDowntimeReports\Radiology /S /M *.* /D -3 /C "cmd /c del @path"
The Clunker
(11 items)
 
Lenovo Y40
(6 items)
 
 
CPUMotherboardGraphicsRAM
Core 2 Quad Q8400 Asus P5P43TD Powercolor 7950 4GB Patriot Viper 
Hard DriveHard DriveCoolingOS
80GB WD Caviar Blue 500GB WD Caviar Black Coolermaster Hyper TX Windows 7 Home Premium 64-bit 
MonitorPowerCase
20" Samsung Corsair CX600M Antec 300 
CPUGraphicsRAMHard Drive
i7-4510U R9 M275 2GB 8GB @ 1600MHz 500+8GB 5400rpm SSHD 
OSMonitor
Windows 8.1 14" 1080p 
  hide details  
Reply
The Clunker
(11 items)
 
Lenovo Y40
(6 items)
 
 
CPUMotherboardGraphicsRAM
Core 2 Quad Q8400 Asus P5P43TD Powercolor 7950 4GB Patriot Viper 
Hard DriveHard DriveCoolingOS
80GB WD Caviar Blue 500GB WD Caviar Black Coolermaster Hyper TX Windows 7 Home Premium 64-bit 
MonitorPowerCase
20" Samsung Corsair CX600M Antec 300 
CPUGraphicsRAMHard Drive
i7-4510U R9 M275 2GB 8GB @ 1600MHz 500+8GB 5400rpm SSHD 
OSMonitor
Windows 8.1 14" 1080p 
  hide details  
Reply
post #6 of 6
Thread Starter 
Quote:
Originally Posted by Tnt6200 View Post

Yes it does. The -3 means the last modified date must be 3 less than or equal to the current date. (i.e. 3 days old)

This will do the same thing, but it's a bit smaller:
Code:
forfiles /P E:\Files\Groups\SoarianDowntimeReports\Radiology /S /M *.* /D -3 /C "cmd /c del @path"

Thanks for taking the time to do this, I really appreciate it! +rep
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need help with a batch file/script