Delete contents of Sub-folder after Time Frame ?
-
CookieMonster
Delete contents of Sub-folder after Time Frame ?
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 ?
-
Filehero
- Posts: 2731
- Joined: 27 Feb 2012 18:50
- Location: Windows 11@100%
Re: Delete contents of Sub-folder after Time Frame ?
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.CookieMonster wrote:...are automatically deleted ?
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 itemCheers,
Filehero
-
CookieMonster
Re: Delete contents of Sub-folder after Time Frame ?
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.<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
-
Filehero
- Posts: 2731
- Joined: 27 Feb 2012 18:50
- Location: Windows 11@100%
Re: Delete contents of Sub-folder after Time Frame ?
Sorry, no more time for asking every single detail.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.
Cheers,
Filehero
-
Filehero
- Posts: 2731
- Joined: 27 Feb 2012 18:50
- Location: Windows 11@100%
Re: Delete contents of Sub-folder after Time Frame ?
How do you think your "scheduling" should happen?CookieMonster wrote:HUH ?
Anyway, I think my pseudo-code at least should help you to begin with writing your script.
Cheers,
Filehero
-
CookieMonster
Re: Delete contents of Sub-folder after Time Frame ?
The scheduling should happen on a specific date that I set in the script !
-
highend
- Posts: 14942
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Delete contents of Sub-folder after Time Frame ?
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.
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.
One of my scripts helped you out? Please donate via Paypal
-
CookieMonster
Re: Delete contents of Sub-folder after Time Frame ?
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 !
-
Filehero
- Posts: 2731
- Joined: 27 Feb 2012 18:50
- Location: Windows 11@100%
Re: Delete contents of Sub-folder after Time Frame ?
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.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.
-> see XY Help|Configuration|Command Line Switches, switch /script.
Cheers,
Filehero
-
CookieMonster
Re: Delete contents of Sub-folder after Time Frame ?
An XY Instance is usually running in the taskbar list, if that counts ?Filehero wrote: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.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.
-> see XY Help|Configuration|Command Line Switches, switch /script.
Cheers,
Filehero
-
Filehero
- Posts: 2731
- Joined: 27 Feb 2012 18:50
- Location: Windows 11@100%
Re: Delete contents of Sub-folder after Time Frame ?
Wether it's maxi- or minimized doesn't matter. You need a regular XY startup as a handler for your script run.CookieMonster wrote:An XY Instance is usually running in the taskbar list, if that counts ?
Cheers,
Filehero
-
PeterH
- Posts: 2827
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: Delete contents of Sub-folder after Time Frame ?
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
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
-
binocular222
- Posts: 1423
- Joined: 04 Nov 2008 05:35
- Location: Win11, Win10, 100% Scaling
Re: Delete contents of Sub-folder after Time Frame ?
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
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
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: Delete contents of Sub-folder after Time Frame ?
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
XYplorer Beta Club