Page 1 of 1

Deleting Folders task

Posted: Wed Aug 02, 2023 6:49 pm
by tlathum
I need a little help creating a task to delete folders that are setup in date format YYYYMMDD that are older than 15yrs. I have to do it by the folder name because the Date Modified doesn't correlate with the folder name date. I just can't get the logic down and would appreciate any help from the community.
FolderNames.png
FolderNames.png (62.49 KiB) Viewed 8309 times

Re: Deleting Folders task

Posted: Fri Aug 04, 2023 12:26 pm
by Oleg
It's very good that you are using the universal date format YYYYMMDD
It makes everything easier

Use File loop action by folders and compare folder name with border date in the loop

Look at my example below. Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.
Next you can see it in task editor

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1163085779
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1004"
Hide=INTEGER|0
ID=INTEGER|-6684713
LogOnAsUser=INTEGER|1
Name=STRING|"Remove old folders (15 years)"
OnErrorTaskID=INTEGER|1879502808
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|2
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FolderName"" with value ""d:\testFolder"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"FolderName"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"FolderName"
varvalue=STRING|"d:\testFolder"

[Actions\Action10]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action11]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""BorderDate"" with value ""{Subtract({Year},15)}{MonthNo}{Day}"""
Params=FOLDER

[Actions\Action2\Params]
_rt_variables_produced=STRING|"BorderDate"
expand=STRING|"1"
linecount=STRING|"1"
varname=STRING|"BorderDate"
varvalue=STRING|"{Subtract({Year},15)}{MonthNo}{Day}"

[Actions\Action3]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action3\Params]
message=STRING|"Border date is: {BorderDate}"
type=STRING|"3"

[Actions\Action4]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER

[Actions\Action4\Params]
_rt_variables_produced=STRING|"CurrentFolder"
createmode=STRING|"1"
date1=STRING|"20230804"
date2=STRING|"20230804"
destvar=STRING|"CurrentFolder"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"{FolderName}\*."
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"1"
sort=STRING|"0"
sortby=STRING|"0"
sortorder=STRING|"0"
subdirs=STRING|"0"
timesize=STRING|"0"
WithoutPath=STRING|"0"

[Actions\Action5]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"5"
type=STRING|"0"
value1=STRING|"{ExtractFileName({CurrentFolder})}"
value2=STRING|"{BorderDate}"

[Actions\Action6]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action6\Params]
message=STRING|"Folder ""{CurrentFolder}"" This folder must be deleted"
type=STRING|"1"

[Actions\Action7]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action7\Params]
message=STRING|"Put here ""Remove folder"" action"
type=STRING|"1"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action9]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action9\Params]
message=STRING|"Folder ""{CurrentFolder}"" skipped"
type=STRING|"3"