Page 1 of 2

Delete contents of Sub-folder after Time Frame ?

Posted: 14 Nov 2013 21:19
by CookieMonster
I'm in need of a script whereas anything that anything that gets placed within each sub-folders has a time limit, after the time limit, whether that is days or weeks the contents within the sub-folders are automatically deleted ?

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 15 Nov 2013 06:37
by Filehero
CookieMonster wrote:...are automatically deleted ?
If automation (that is, sweep run triggered manually is not tolerated) is the key requirement you need something like the windows task scheduler. Wether you fire up an XY or Powershell script or whatever is a another question.

The abstract logic could be:

Code: Select all

for [item in listToCheck]
  if [ ( (item.createDate or item.modifyDate or item.accessDate) - (TODAY or NOW) ) is greater than MAX_LIFETIME ]
    then delete item
Anyway, your requirments need to become much clearer, I'm afraid.


Cheers,
Filehero

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 15 Nov 2013 06:57
by CookieMonster
<folder>
----<sub folder a> / Files placed in this folder are deleted after 4 weeks
--<sub folder b> / Files placed in this folder are deleted after 3.5 weeks
-<sub folder c> / Files placed in this folder are deleted after 2 weeks
The cycle resets, and waits until the desired time period expires, rinse and repeat after the desired time period expires. Only those sub-folder within a folder, no other directory or sub-folder on the computer.

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 15 Nov 2013 07:22
by Filehero
CookieMonster wrote:The cycle resets, and waits until the desired time period expires, rinse and repeat after the desired time period expires. Only those sub-folder within a folder, no other directory or sub-folder on the computer.
Sorry, no more time for asking every single detail.


Cheers,
Filehero

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 15 Nov 2013 07:28
by CookieMonster
HUH ?

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 15 Nov 2013 16:30
by Filehero
CookieMonster wrote:HUH ?
How do you think your "scheduling" should happen?

Anyway, I think my pseudo-code at least should help you to begin with writing your script. :wink:


Cheers,
Filehero

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 15 Nov 2013 22:34
by CookieMonster
The scheduling should happen on a specific date that I set in the script !

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 15 Nov 2013 22:47
by highend
There is no real scheduling possible (at least not from inside XY), you'll always have to execute the script yourself. So it makes no sense to use static date values in a script.

Create a list of folders, and after each one (separated by e.g. "|") the timeframe.
Loop over the list (foreach) and use gettoken() to get the different entries.
Filehero has already shown how time calculation could be done.

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 17 Nov 2013 18:38
by CookieMonster
As you say, if I have to manually run the script all the time, I could just delete the files in a folder manually. I suppose I'll try something outside of XY !

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 17 Nov 2013 20:04
by Filehero
CookieMonster wrote:As you say, if I have to manually run the script all the time, I could just delete the files in a folder manually.
Not being able to schedul eit from within XY does not necessarily mean you have to run it manually all the time: you could couple the script run to XY's start. Assumed you start a XY instance at least once per week you'll achieve a weekly job this way.

-> see XY Help|Configuration|Command Line Switches, switch /script.


Cheers,
Filehero

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 17 Nov 2013 21:40
by CookieMonster
Filehero wrote:
CookieMonster wrote:As you say, if I have to manually run the script all the time, I could just delete the files in a folder manually.
Not being able to schedul eit from within XY does not necessarily mean you have to run it manually all the time: you could couple the script run to XY's start. Assumed you start a XY instance at least once per week you'll achieve a weekly job this way.

-> see XY Help|Configuration|Command Line Switches, switch /script.


Cheers,
Filehero
An XY Instance is usually running in the taskbar list, if that counts ?

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 18 Nov 2013 06:26
by Filehero
CookieMonster wrote:An XY Instance is usually running in the taskbar list, if that counts ?
Wether it's maxi- or minimized doesn't matter. You need a regular XY startup as a handler for your script run.


Cheers,
Filehero

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 18 Nov 2013 11:49
by PeterH
You could post a request to Don for maybe 2 new scripting commands:

at(command, date, time) - execute command at specified date/time
every(command, interval) - repeatedly execute command after interval (days/hh:mm:ss)

And some means to "purge" those timers at will.

I would second that :mrgreen:

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 18 Nov 2013 11:57
by binocular222
You can already made a constantly running script by something like:
while( 1==1) {
msg Hi;
wait 5000}
But that would loop foreer and you cannot execute any other script.
A much easier solution is using 3rd party software. i.e: A very simple AHK script would do the trick

Re: Delete contents of Sub-folder after Time Frame ?

Posted: 18 Nov 2013 14:26
by Enternal
Yeah it's not possible to completely run the script with just XYplorer like many have said. Autohotkey is a great idea to rerun the script over a certain time period. Here's an example:

Code: Select all

#Persistent
InputBox, TimeMinutes, Minutes, How Many Minutes to Rerun?, , 250, 100
If TimeMinutes Is Not Number
	{
	MsgBox, Invalid Value for Minutes. Cannot Continue.
	ExitApp
	}
TimeMilli := TimeMinutes*60*1000

SetTimer, RunApp, %TimeMilli%
Return

RunApp:
;FormatTime, TimeString, , Time
;MsgBox, The Current Time is %TimeString%
Run, Application.exe
Return