renaming files with sequence number
renaming files with sequence number
Hello!I have problem with renaming files. I must rename files like this:aaa.txt to aaa.001 (leading zeros must be included in sequence num.)bbb.txt to bbb.002ccc.txt to ccc.003..hhh.txt to hhh.999I would like to say that I receive files randomly (they don't come together).Another think must be mentioned: this sequence number (file extension) must start with new day with 001.Thank you for your HELP!Borut
renaming files with sequence number
Explain the task in more details, please
I understand so:
When new TXT file appears in the folder you should change its extension to number (001, 002, etc)
In next month you should reset the sequence to beginning.
I think that possible the conflict of file names if new files will appear in the same folder
I understand so:
When new TXT file appears in the folder you should change its extension to number (001, 002, etc)
In next month you should reset the sequence to beginning.
I think that possible the conflict of file names if new files will appear in the same folder
renaming files with sequence number
See the example below.
This task changes file extension TXT to 001, 002, 003, etc in folder D:\incoming
Counter will be reset in next month.
Save the text of the task into a file and use menu Task=>Import
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|2099193306
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task73"
Hide=INTEGER|0
ID=INTEGER|492727294
LogOnAsUser=INTEGER|1
Name=STRING|"Change extensions to numbers"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action1\Params]
case=STRING|"0"
operator=STRING|"1"
type=STRING|"0"
value1=STRING|"{CurrentMonth}"
value2=STRING|"{MonthNo}"
[Actions\Action10]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action11]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|0
Name=STRING|"Show ""{currentnum}"""
Params=FOLDER
[Actions\Action11\Params]
icon=STRING|"1"
msg0=STRING|"{currentnum}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action12]
ActionID=STRING|"A_FILE_RENAME"
Enabled=INTEGER|-1
Name=STRING|"Rename File"
Params=FOLDER
[Actions\Action12\Params]
count=STRING|"1"
file0=STRING|"{c_file}"
ifexists=STRING|"0"
mask=STRING|"*.{currentnum}"
subdirs=STRING|"0"
[Actions\Action13]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""currentnum"""
Params=FOLDER
[Actions\Action13\Params]
incement=STRING|"1"
vaiable=STRING|"currentnum"
[Actions\Action14]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create global variable ""CURRENTMONTH"" with value ""{MonthNo}"""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"1"
varkind=STRING|"0"
varname=STRING|"CURRENTMONTH"
varvalue=STRING|"{MonthNo}"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create global variable ""CURRENTNUM"" with value ""1"""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varkind=STRING|"0"
varname=STRING|"CURRENTNUM"
varvalue=STRING|"1"
[Actions\Action4]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action5]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""C_FILE"" with value """""
Params=FOLDER
[Actions\Action5\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"C_FILE"
[Actions\Action6]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER
[Actions\Action6\Params]
createmode=STRING|"1"
date1=STRING|"20130116"
date2=STRING|"20130116"
destvar=STRING|"C_FILE"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"D:\incoming\*.txt"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
subdirs=STRING|"0"
timesize=STRING|"0"
WithoutPath=STRING|"0"
[Actions\Action7]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//add leading zeros"
Params=FOLDER
[Actions\Action7\Params]
comment=STRING|"add leading zeros"
[Actions\Action8]
ActionID=STRING|"A_LOOP_WHILE"
Enabled=INTEGER|-1
Name=STRING|"While loop"
Params=FOLDER
[Actions\Action8\Params]
case=STRING|"0"
operator=STRING|"5"
type=STRING|"1"
value1=STRING|"{StrLength({currentnum})}"
value2=STRING|"3"
[Actions\Action9]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CURRENTNUM"" with value ""0{CURRENTNUM}"""
Params=FOLDER
[Actions\Action9\Params]
expand=STRING|"1"
varname=STRING|"CURRENTNUM"
varvalue=STRING|"0{CURRENTNUM}"
This task changes file extension TXT to 001, 002, 003, etc in folder D:\incoming
Counter will be reset in next month.
Save the text of the task into a file and use menu Task=>Import
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|2099193306
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task73"
Hide=INTEGER|0
ID=INTEGER|492727294
LogOnAsUser=INTEGER|1
Name=STRING|"Change extensions to numbers"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action1\Params]
case=STRING|"0"
operator=STRING|"1"
type=STRING|"0"
value1=STRING|"{CurrentMonth}"
value2=STRING|"{MonthNo}"
[Actions\Action10]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action11]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|0
Name=STRING|"Show ""{currentnum}"""
Params=FOLDER
[Actions\Action11\Params]
icon=STRING|"1"
msg0=STRING|"{currentnum}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action12]
ActionID=STRING|"A_FILE_RENAME"
Enabled=INTEGER|-1
Name=STRING|"Rename File"
Params=FOLDER
[Actions\Action12\Params]
count=STRING|"1"
file0=STRING|"{c_file}"
ifexists=STRING|"0"
mask=STRING|"*.{currentnum}"
subdirs=STRING|"0"
[Actions\Action13]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""currentnum"""
Params=FOLDER
[Actions\Action13\Params]
incement=STRING|"1"
vaiable=STRING|"currentnum"
[Actions\Action14]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create global variable ""CURRENTMONTH"" with value ""{MonthNo}"""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"1"
varkind=STRING|"0"
varname=STRING|"CURRENTMONTH"
varvalue=STRING|"{MonthNo}"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create global variable ""CURRENTNUM"" with value ""1"""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varkind=STRING|"0"
varname=STRING|"CURRENTNUM"
varvalue=STRING|"1"
[Actions\Action4]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action5]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""C_FILE"" with value """""
Params=FOLDER
[Actions\Action5\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"C_FILE"
[Actions\Action6]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER
[Actions\Action6\Params]
createmode=STRING|"1"
date1=STRING|"20130116"
date2=STRING|"20130116"
destvar=STRING|"C_FILE"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"D:\incoming\*.txt"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
subdirs=STRING|"0"
timesize=STRING|"0"
WithoutPath=STRING|"0"
[Actions\Action7]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//add leading zeros"
Params=FOLDER
[Actions\Action7\Params]
comment=STRING|"add leading zeros"
[Actions\Action8]
ActionID=STRING|"A_LOOP_WHILE"
Enabled=INTEGER|-1
Name=STRING|"While loop"
Params=FOLDER
[Actions\Action8\Params]
case=STRING|"0"
operator=STRING|"5"
type=STRING|"1"
value1=STRING|"{StrLength({currentnum})}"
value2=STRING|"3"
[Actions\Action9]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CURRENTNUM"" with value ""0{CURRENTNUM}"""
Params=FOLDER
[Actions\Action9\Params]
expand=STRING|"1"
varname=STRING|"CURRENTNUM"
varvalue=STRING|"0{CURRENTNUM}"
renaming files with sequence number
Hello Oleg!Thank you for your prompt reply and assistance. Here I attach an example of how I solved the issue:The variables are built as follows:DATUM -> {YEAR}{MONTHNO}{DAY}DAT_K -> {SHORTYEAR}{MONTHNO}{DAY};*****************************;* RoboTask Task file;* Do not edit in text editor!;***************************** [Root]ActionAfterRun=INTEGER|0Actions=FOLDERAutomat=INTEGER|-1CatID=INTEGER|157584294Comment=STRINGLISTContinueOnError=INTEGER|0Events=FOLDERExternalName=STRING|"Task25"Hide=INTEGER|0ID=INTEGER|1512166711LogOnAsUser=INTEGER|1Name=STRING|"Rename_files_SEQ_NUM"OnErrorTaskID=INTEGER|0Priority=INTEGER|3RunOnClose=INTEGER|0RunOnStartup=INTEGER|0ToLog=INTEGER|3WriteGeneralLog=INTEGER|0[Actions]Action1=FOLDERAction10=FOLDERAction11=FOLDERAction12=FOLDERAction13=FOLDERAction2=FOLDERAction3=FOLDERAction4=FOLDERAction5=FOLDERAction6=FOLDERAction7=FOLDERAction8=FOLDERAction9=FOLDER[Actions\Action1]ActionID=STRING|"A_VARIABLES_SET"Enabled=INTEGER|-1Name=STRING|"Set variable ""ST_DAT"" with value ""0"""Params=FOLDER[Actions\Action1\Params]expand=STRING|"1"varname=STRING|"ST_DAT"varvalue=STRING|"0"[Actions\Action10]ActionID=STRING|"A_VARIABLES_SET"Enabled=INTEGER|-1Name=STRING|"Set variable ""ST_DAT"" with value ""0{ST_DAT}"""Params=FOLDER[Actions\Action10\Params]expand=STRING|"1"varname=STRING|"ST_DAT"varvalue=STRING|"0{ST_DAT}"[Actions\Action11]ActionID=STRING|"A_LOOP_END"Enabled=INTEGER|-1Name=STRING|"End Loop"[Actions\Action12]ActionID=STRING|"A_FILE_RENAME"Enabled=INTEGER|-1Name=STRING|"Rename File"Params=FOLDER[Actions\Action12\Params]count=STRING|"1"file0=STRING|"C:\robotask\temp\2\{DATO}"ifexists=STRING|"0"mask=STRING|"P2{DAT_K}.{ST_DAT}"subdirs=STRING|"0"[Actions\Action13]ActionID=STRING|"A_LOOP_END"Enabled=INTEGER|-1Name=STRING|"End Loop"[Actions\Action2]ActionID=STRING|"A_LOOP_FILE"Enabled=INTEGER|-1Name=STRING|"File Loop"Params=FOLDER[Actions\Action2\Params]createmode=STRING|"1"date1=STRING|"20130115"date2=STRING|"20130115"destvar=STRING|"AAA"DuringDays=STRING|"1"DuringHours=STRING|"1"DuringMinutes=STRING|"1"DuringMonths=STRING|"1"file0=STRING|"C:\robotask\temp\2\P2{DAT_K}*.*"filecount=STRING|"1"OlderDays=STRING|"1"OlderHours=STRING|"1"OlderMinutes=STRING|"1"OlderMonths=STRING|"1"savesize=STRING|"0"searchkind=STRING|"0"subdirs=STRING|"0"timesize=STRING|"0"WithoutPath=STRING|"0"[Actions\Action3]ActionID=STRING|"A_VARIABLES_INCREMENT"Enabled=INTEGER|-1Name=STRING|"Increment variable ""ST_DAT"""Params=FOLDER[Actions\Action3\Params]incement=STRING|"1"vaiable=STRING|"ST_DAT"[Actions\Action4]ActionID=STRING|"A_LOOP_END"Enabled=INTEGER|-1Name=STRING|"End Loop"[Actions\Action5]ActionID=STRING|"A_LOOP_FILE"Enabled=INTEGER|-1Name=STRING|"File Loop"Params=FOLDER[Actions\Action5\Params]createmode=STRING|"1"date1=STRING|"20130116"date2=STRING|"20130116"destvar=STRING|"DATO"DuringDays=STRING|"1"DuringHours=STRING|"1"DuringMinutes=STRING|"1"DuringMonths=STRING|"1"file0=STRING|"C:\robotask\temp\1\{DATUM}*.out"filecount=STRING|"1"OlderDays=STRING|"1"OlderHours=STRING|"1"OlderMinutes=STRING|"1"OlderMonths=STRING|"1"savesize=STRING|"0"searchkind=STRING|"0"subdirs=STRING|"0"timesize=STRING|"0"WithoutPath=STRING|"1"[Actions\Action6]ActionID=STRING|"A_FILE_COPY"Enabled=INTEGER|-1Name=STRING|"Copy/Move File"Params=FOLDER[Actions\Action6\Params]destdir=STRING|"C:\robotask\temp\2\"f_count=STRING|"1"file0=STRING|"C:\robotask\temp\1\{DATO}"hidden=STRING|"0"ifexists=STRING|"0"move=STRING|"1"subdir=STRING|"0"system=STRING|"0"[Actions\Action7]ActionID=STRING|"A_VARIABLES_INCREMENT"Enabled=INTEGER|-1Name=STRING|"Increment variable ""ST_DAT"""Params=FOLDER[Actions\Action7\Params]incement=STRING|"1"vaiable=STRING|"ST_DAT"[Actions\Action8]ActionID=STRING|"A_LOOP_WHILE"Enabled=INTEGER|-1Name=STRING|"While loop"Params=FOLDER[Actions\Action8\Params]case=STRING|"0"operator=STRING|"5"type=STRING|"1"value1=STRING|"{StrLength({ST_DAT})}"value2=STRING|"3"[Actions\Action9]ActionID=STRING|"A_MISC_COMMENT"Enabled=INTEGER|-1Name=STRING|"//Adding leading zeros"Params=FOLDER[Actions\Action9\Params]comment=STRING|"Adding leading zeros"[Events]Event1=FOLDER[Events\Event1]Enabled=INTEGER|-1EventID=STRING|"E_FILE_MONITOR"Params=FOLDERUnigueID=INTEGER|91444552[Events\Event1\Params]chg=STRING|"0"chga=STRING|"1"chgsl=STRING|"1"chgsm=STRING|"1"chgtl=STRING|"1"chgtm=STRING|"1"del=STRING|"0"folder1=STRING|"C:\robotask\temp\1"foldercount=STRING|"1"id=STRING|"3W8KIOKZF"incmask=STRING|"{DATUM}*.out"interval=STRING|"10"listmode=STRING|"1"mon_files=STRING|"1"mon_folders=STRING|"1"new=STRING|"1"onelist=STRING|"C:\robotask\temp\loglist.txt"saveresults=STRING|"0"subfolders1=STRING|"0"