WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
Delete folders older than x days (Read 282 times)
BGEtest
YaBB Newbies
*
Offline



Posts: 4
Delete folders older than x days
Mar 27th, 2017 at 6:07pm
 
I'm wondering if there is a plugin or a way to delete folders olden than x number of days. What I need to do is keep folders in a directory for x number of days then run a event to delete older folder.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2217
The Netherlands
Re: Delete folders older than x days
Reply #1 - Mar 28th, 2017 at 7:20pm
 
Hi,

If those folders are EMPTY...
Use the "delete files" task (it can also do folders). On the "Events" window, make sure to set the DIRNEW option.
On "Monitoring Method" use the "File Age" method and set the number of minutes/hours/days to wait. Do NOT set the option "Remember triggered files".

If the folders are NOT empty, you can do the same setup as above but use the "Run a .bat file script". The script can remove the folder plus its contents. Let me know if you need help with the script.

Gert
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
BGEtest
YaBB Newbies
*
Offline



Posts: 4
Re: Delete folders older than x days
Reply #2 - Mar 29th, 2017 at 8:53pm
 
Yes I need help with script, i assume i would need a batch script that will work with a UNC path.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2217
The Netherlands
Re: Delete folders older than x days
Reply #3 - Mar 30th, 2017 at 10:56am
 
It is actually a very simple script, call it for example C:\Scripts\RemoveDir.bat and it should have the following contents:
Code:
ECHO Directory "%WD_FILE%" will be deleted >> "C:\logs\RemoveDir_%WD_DATE%.txt"
RM /S "%WD_FILE%"
 



This will remove the detected directory, sub-directories and all files within. It will also write a line of text to C:\Logs\RemoveDir_YYYYMMDD.txt

Like I wrote earlier:
On "Events" only select "DIRNEW"
On "Monitoring method" select "File age" and do not set "remember triggered files"

If you need to test first (only write to the log file, not actually removing the directory) change the script to
Code:
ECHO Directory "%WD_FILE%" will be deleted >> "C:\logs\RemoveDir_%WD_DATE%.txt"
REM RM /S "%WD_FILE%"
 


Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Page Index Toggle Pages: 1