WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> Plugins >> Delete folders older than x days
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1490630840

Message started by BGEtest on Mar 27th, 2017 at 6:07pm

Title: Delete folders older than x days
Post by BGEtest on 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.

Title: Re: Delete folders older than x days
Post by Gert on 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

Title: Re: Delete folders older than x days
Post by BGEtest on 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.

Title: Re: Delete folders older than x days
Post by Gert on 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%"
[/code):

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%"


WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.