Page 1 of 1

Anyone using Robotask to monitor a folder and automatically rename + move files based on filename pattern?

Posted: Tue Mar 31, 2026 7:49 am
by pumpedboring
Hi everyone, I’m trying to set up a task in RoboTask where it monitors a specific folder, and whenever a new file is added, it checks the filename for a certain pattern, then renames the file and moves it to a different folder based on that pattern. I’ve managed to get the folder monitoring working, but I’m stuck on the part where RoboTask reads part of the filename and uses it in the new filename or destination folder.

For example, if a file named INV_2026_003.pdf is added, I want RoboTask to automatically rename it to Invoice_003.pdf and move it to a folder called 2026 Invoices. I think this should be possible using variables, but I’m not sure which actions and variables to use together (File Parser? Replace Text? Set Variable?).

If someone has done something similar, could you share a simple step-by-step setup or example task? Thanks in advance!

Re: Anyone using Robotask to monitor a folder and automatically rename + move files based on filename pattern?

Posted: Tue Mar 31, 2026 4:20 pm
by Oleg
You will most likely need to use regular expressions. This is the easiest way to check the file name pattern and extract the necessary parameters from the name.
Take a look at my example (see below)
First, the task checks the file name pattern. The file name must be in the following format:
INV_YYYY_NNN.pdf
where YYYY is the year
NNN is the invoice number

If the pattern matches, it extracts the year and number from the file name
Then it generates a new file name and folder name
You probably already know how to rename and move a file.

Here is the example. Save the task text to a file and use the Task->Import menu to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|307868550
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1466"
Hide=INTEGER|0
ID=INTEGER|-589542707
LogOnAsUser=INTEGER|1
Name=STRING|"Get new name and target forder from filename"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RestrictRESTAPIAccess=INTEGER|0
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=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 ""_SourceFileName"" with value ""INV_2026_003.pdf"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"_SourceFileName"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"_SourceFileName"
varvalue=STRING|"INV_2026_003.pdf"

[Actions\Action2]
ActionID=STRING|"A_REGEXP_MATCH"
Enabled=INTEGER|-1
Name=STRING|"RegExp Match"
Params=FOLDER

[Actions\Action2\Params]
_rt_variables_produced=STRING|"_expression,_matched"
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{_SourceFileName}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"(?i)inv_(\d{4})_(\d+).pdf"
savesubexpression=STRING|"1"
singleline=STRING|"0"
subexpressionpos=STRING|"0"
subexpressionvar=STRING|"_expression"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"_matched"

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

[Actions\Action3\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{_matched}"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""TargetName"" with value ""Invoice_{_expression(2)}.pdf"""
Params=FOLDER

[Actions\Action4\Params]
_rt_variables_produced=STRING|"TargetName"
expand=STRING|"1"
linecount=STRING|"1"
varname=STRING|"TargetName"
varvalue=STRING|"Invoice_{_expression(2)}.pdf"

[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""TargetFolder"" with value ""{_expression(1)} invoices"""
Params=FOLDER

[Actions\Action5\Params]
_rt_variables_produced=STRING|"TargetFolder"
expand=STRING|"1"
linecount=STRING|"1"
varname=STRING|"TargetFolder"
varvalue=STRING|"{_expression(1)} invoices"

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Source file name: {_SourceFileName}"""
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"1"
msg0=STRING|"Source file name: {_SourceFileName}"
msg1=STRING|"Target file name: {TargetName}"
msg2=STRING|"Target folder: {TargetFolder}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"

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

[Actions\Action8]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""The file name does not match the pattern ""INV_YYYY_NNN.pdf"""""
Params=FOLDER

[Actions\Action8\Params]
icon=STRING|"3"
msg0=STRING|"The file name does not match the pattern ""INV_YYYY_NNN.pdf"""
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

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