rename files

Discuss RoboTask here
Post Reply
merle
Posts: 15
Joined: Thu Sep 21, 2006 5:48 pm

rename files

Post by merle »

Hi Oleg,I am trying to rename some files that do to a file naming error created them out of order.I just need to RT look at first word make it var 1then look at 2nd word make it var 2then rename the entire file to be output with var2, var1 and the rest of file nameexpampleMerle Pendos - Dang I need to know how to program.txtwould become Pendos, Merle - Dang I need to know how to program.txtThanks so much
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

rename files

Post by Oleg »

Look at the example below.
This task does the following:
- Divide the name of file into two parts - before hyphen and after
- Form the new file name: 2-nd word, comma, 1-st word, hyphen, 2-nd part, dot, TXT

The restrictions of this task are:
- file name must have hyphen
- first part must have two words

;**********************
;* RoboTask Task file *
;* Do not edit!       *
;**********************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1947094105
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task512"
Hide=INTEGER|0
ID=INTEGER|221553704
Name=STRING|"Genarate new name"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FILENAME"" with value ""Merle Pendos - Dang I need to know how to program.txt"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"FILENAME"
varvalue=STRING|"Merle Pendos - Dang I need to know how to program.txt"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Old file name is:"""
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"Old file name is:"
msg1=STRING|"{filename}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_DELIMITED"
Enabled=INTEGER|-1
Name=STRING|"Delimited Variable"
Params=FOLDER

[Actions\Action3\Params]
colon=STRING|"0"
comma=STRING|"0"
other=STRING|"1"
otherchar=STRING|"-"
quote=STRING|"0"
semocolon=STRING|"0"
space=STRING|"0"
spaceasone=STRING|"0"
string=STRING|"{ExtractFileNameNoExt({filename})}"
tab=STRING|"0"
variable=STRING|"var1"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""VAR2"" with value ""{var1(0)}"""
Params=FOLDER

[Actions\Action4\Params]
expand=STRING|"1"
varname=STRING|"VAR2"
varvalue=STRING|"{var1(0)}"

[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FILENAME"" with value ""{var2(1)}, {var2(0)} - {var1(1)}.txt"""
Params=FOLDER

[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"FILENAME"
varvalue=STRING|"{var2(1)}, {var2(0)} - {var1(1)}.txt"

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""New file name is:"""
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"1"
msg0=STRING|"New file name is:"
msg1=STRING|"{filename}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"
merle
Posts: 15
Joined: Thu Sep 21, 2006 5:48 pm

rename files

Post by merle »

Thanks Oleg!I have changed it around here somewhat.My question/problem is if I have more than one file in there it does not work. Can you help?It works fine on first file and renames and moves the first file. I would like for it to loop back and change the other names but my copy file command seems to be grabbing all files after 1st one is name changed.here is what I have.;**********************;* RoboTask Task file *;* Do not edit!       *;********************** [Root]ActionAfterRun=INTEGER|0Actions=FOLDERAutomat=INTEGER|0CatID=INTEGER|0ContinueOnError=INTEGER|0ExternalName=STRING|"Task21"Hide=INTEGER|0ID=INTEGER|1069012521Name=STRING|"Copy of Genarate new name (imported)"Priority=INTEGER|3RunOnClose=INTEGER|0RunOnStartup=INTEGER|0ToLog=INTEGER|3[Actions]Action1=FOLDERAction10=FOLDERAction11=FOLDERAction12=FOLDERAction13=FOLDERAction2=FOLDERAction3=FOLDERAction4=FOLDERAction5=FOLDERAction6=FOLDERAction7=FOLDERAction8=FOLDERAction9=FOLDER[Actions\Action1]ActionID=STRING|"A_LOOP_FILE"Enabled=INTEGER|-1Name=STRING|"File Loop"Params=FOLDER[Actions\Action1\Params]createmode=STRING|"1"date1=STRING|"20070821"date2=STRING|"20070821"destvar=STRING|"FILENAME"DuringDays=STRING|"1"DuringMonths=STRING|"1"file0=STRING|"H:\switchnamesfiles\*.*"filecount=STRING|"1"OlderDays=STRING|"1"OlderMonths=STRING|"1"savesize=STRING|"0"searchkind=STRING|"0"subdirs=STRING|"1"timesize=STRING|"0"WithoutPath=STRING|"0"[Actions\Action10]ActionID=STRING|"A_LOOP_END"Enabled=INTEGER|-1Name=STRING|"End Loop"[Actions\Action11]ActionID=STRING|"A_VARIABLES_REMOVE"Enabled=INTEGER|-1Name=STRING|"Remove variable ""FILENAME"""Params=FOLDER[Actions\Action11\Params]varname=STRING|"FILENAME"[Actions\Action12]ActionID=STRING|"A_VARIABLES_REMOVE"Enabled=INTEGER|-1Name=STRING|"Remove variable ""VAR1"""Params=FOLDER[Actions\Action12\Params]varname=STRING|"VAR1"[Actions\Action13]ActionID=STRING|"A_VARIABLES_REMOVE"Enabled=INTEGER|-1Name=STRING|"Remove variable ""VAR2"""Params=FOLDER[Actions\Action13\Params]varname=STRING|"VAR2"[Actions\Action2]ActionID=STRING|"A_DIALOG_MESSAGE"Enabled=INTEGER|0Name=STRING|"Show ""Old file name is:"""Params=FOLDER[Actions\Action2\Params]icon=STRING|"1"msg0=STRING|"Old file name is:"msg1=STRING|"{filename}"msgcount=STRING|"2"playsound=STRING|"0"showmessage=STRING|"1"[Actions\Action3]ActionID=STRING|"A_VARIABLES_DELIMITED"Enabled=INTEGER|-1Name=STRING|"Delimited Variable"Params=FOLDER[Actions\Action3\Params]colon=STRING|"0"comma=STRING|"0"other=STRING|"1"otherchar=STRING|"-"quote=STRING|"0"semocolon=STRING|"0"space=STRING|"0"spaceasone=STRING|"0"string=STRING|"{ExtractFileName({filename})}"tab=STRING|"0"variable=STRING|"var1"[Actions\Action4]ActionID=STRING|"A_VARIABLES_SET"Enabled=INTEGER|-1Name=STRING|"Set variable ""VAR2"" with value ""{var1(0)}"""Params=FOLDER[Actions\Action4\Params]expand=STRING|"1"varname=STRING|"VAR2"varvalue=STRING|"{var1(0)}"[Actions\Action5]ActionID=STRING|"A_VARIABLES_SET"Enabled=INTEGER|-1Name=STRING|"Set variable ""FILENAME"" with value ""{var2(1)}, {var2(0)} - {var1(1)}"""Params=FOLDER[Actions\Action5\Params]expand=STRING|"1"varname=STRING|"FILENAME"varvalue=STRING|"{var2(1)}, {var2(0)} - {var1(1)}"[Actions\Action6]ActionID=STRING|"A_DIALOG_MESSAGE"Enabled=INTEGER|0Name=STRING|"Show ""New file name is:"""Params=FOLDER[Actions\Action6\Params]icon=STRING|"1"msg0=STRING|"New file name is:"msg1=STRING|"{filename}"msgcount=STRING|"2"playsound=STRING|"0"showmessage=STRING|"1"[Actions\Action7]ActionID=STRING|"A_FILE_RENAME"Enabled=INTEGER|-1Name=STRING|"Rename File"Params=FOLDER[Actions\Action7\Params]count=STRING|"1"file0=STRING|"{filename}"mask=STRING|"{var2(1)}, {var2(0)} - {var1(1)}"subdirs=STRING|"1"[Actions\Action8]ActionID=STRING|"A_GENERAL_PAUSE"Enabled=INTEGER|-1Name=STRING|"Delay 1000 ms"Params=FOLDER[Actions\Action8\Params]delay=STRING|"10"[Actions\Action9]ActionID=STRING|"A_FILE_COPY"Enabled=INTEGER|-1Name=STRING|"Copy/Move File"Params=FOLDER[Actions\Action9\Params]destdir=STRING|"H:\z individual files to be sorted\"f_count=STRING|"1"file0=STRING|"H:\switchnamesfiles\*.*"ifexists=STRING|"0"move=STRING|"1"subdir=STRING|"0"
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

rename files

Post by Oleg »

I think that you need to remove 5-th step (Set variable "FILENAME" with value "{var2(1)}, {var2(0)} - {var1(1)}")
Also, maybe you need to move the step "Copy/Move File" to outside of the loop.

See my improvements below:

;**********************
;* RoboTask Task file *
;* Do not edit!       *
;**********************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|1947094105
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task513"
Hide=INTEGER|0
ID=INTEGER|1069012521
Name=STRING|"Genarate new name with improvements"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3

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

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

[Actions\Action1\Params]
createmode=STRING|"1"
date1=STRING|"20070821"
date2=STRING|"20070821"
destvar=STRING|"FILENAME"
DuringDays=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"H:\switchnamesfiles\*.*"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
subdirs=STRING|"1"
timesize=STRING|"0"
WithoutPath=STRING|"0"

[Actions\Action10]
ActionID=STRING|"A_FILE_COPY"
Enabled=INTEGER|-1
Name=STRING|"Copy/Move File"
Params=FOLDER

[Actions\Action10\Params]
destdir=STRING|"H:\z individual files to be sorted\"
f_count=STRING|"1"
file0=STRING|"H:\switchnamesfiles\*.*"
ifexists=STRING|"0"
move=STRING|"1"
subdir=STRING|"0"

[Actions\Action11]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""FILENAME"""
Params=FOLDER

[Actions\Action11\Params]
varname=STRING|"FILENAME"

[Actions\Action12]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""VAR1"""
Params=FOLDER

[Actions\Action12\Params]
varname=STRING|"VAR1"

[Actions\Action13]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""VAR2"""
Params=FOLDER

[Actions\Action13\Params]
varname=STRING|"VAR2"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|0
Name=STRING|"Show ""Old file name is:"""
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"Old file name is:"
msg1=STRING|"{filename}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_DELIMITED"
Enabled=INTEGER|-1
Name=STRING|"Delimited Variable"
Params=FOLDER

[Actions\Action3\Params]
colon=STRING|"0"
comma=STRING|"0"
other=STRING|"1"
otherchar=STRING|"-"
quote=STRING|"0"
semocolon=STRING|"0"
space=STRING|"0"
spaceasone=STRING|"0"
string=STRING|"{ExtractFileName({filename})}"
tab=STRING|"0"
variable=STRING|"var1"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""VAR2"" with value ""{var1(0)}"""
Params=FOLDER

[Actions\Action4\Params]
expand=STRING|"1"
varname=STRING|"VAR2"
varvalue=STRING|"{var1(0)}"

[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|0
Name=STRING|"Set variable ""FILENAME"" with value ""{var2(1)}, {var2(0)} - {var1(1)}"""
Params=FOLDER

[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"FILENAME"
varvalue=STRING|"{var2(1)}, {var2(0)} - {var1(1)}"

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|0
Name=STRING|"Show ""New file name is:"""
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"1"
msg0=STRING|"New file name is:"
msg1=STRING|"{filename}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action7]
ActionID=STRING|"A_FILE_RENAME"
Enabled=INTEGER|-1
Name=STRING|"Rename File"
Params=FOLDER

[Actions\Action7\Params]
count=STRING|"1"
file0=STRING|"{filename}"
mask=STRING|"{var2(1)}, {var2(0)} - {var1(1)}"
subdirs=STRING|"1"

[Actions\Action8]
ActionID=STRING|"A_GENERAL_PAUSE"
Enabled=INTEGER|-1
Name=STRING|"Delay 1000 ms"
Params=FOLDER

[Actions\Action8\Params]
delay=STRING|"10"

[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
merle
Posts: 15
Joined: Thu Sep 21, 2006 5:48 pm

rename files

Post by merle »

Hey Olegg thanks! Two more questions if I could , some files have a second "-" in them. Example Merle Pendos - Dang I need to know how to program - cause I have not done it in 20 years.txtThis cause it to break with error.The second question would be what about files that do not have a "-" in them? Example Merle Pendos Dang I need to know how to program.txtOR if not possible to do these two easily, can you think of a simple
way to have it move the file (to another folder) where either of the
two conditions occurs?  As always thanks so much.
Oleg wrote:I think that you need to remove 5-th step (Set variable "FILENAME" with value "{var2(1)}, {var2(0)} - {var1(1)}")
Also, maybe you need to move the step "Copy/Move File" to outside of the loop.

See my improvements below:

;**********************
;* RoboTask Task file *
;* Do not edit!       *
;**********************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|1947094105
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task513"
Hide=INTEGER|0
ID=INTEGER|1069012521
Name=STRING|"Genarate new name with improvements"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3

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

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

[Actions\Action1\Params]
createmode=STRING|"1"
date1=STRING|"20070821"
date2=STRING|"20070821"
destvar=STRING|"FILENAME"
DuringDays=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"H:\switchnamesfiles\*.*"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
subdirs=STRING|"1"
timesize=STRING|"0"
WithoutPath=STRING|"0"

[Actions\Action10]
ActionID=STRING|"A_FILE_COPY"
Enabled=INTEGER|-1
Name=STRING|"Copy/Move File"
Params=FOLDER

[Actions\Action10\Params]
destdir=STRING|"H:\z individual files to be sorted\"
f_count=STRING|"1"
file0=STRING|"H:\switchnamesfiles\*.*"
ifexists=STRING|"0"
move=STRING|"1"
subdir=STRING|"0"

[Actions\Action11]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""FILENAME"""
Params=FOLDER

[Actions\Action11\Params]
varname=STRING|"FILENAME"

[Actions\Action12]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""VAR1"""
Params=FOLDER

[Actions\Action12\Params]
varname=STRING|"VAR1"

[Actions\Action13]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""VAR2"""
Params=FOLDER

[Actions\Action13\Params]
varname=STRING|"VAR2"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|0
Name=STRING|"Show ""Old file name is:"""
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"Old file name is:"
msg1=STRING|"{filename}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_DELIMITED"
Enabled=INTEGER|-1
Name=STRING|"Delimited Variable"
Params=FOLDER

[Actions\Action3\Params]
colon=STRING|"0"
comma=STRING|"0"
other=STRING|"1"
otherchar=STRING|"-"
quote=STRING|"0"
semocolon=STRING|"0"
space=STRING|"0"
spaceasone=STRING|"0"
string=STRING|"{ExtractFileName({filename})}"
tab=STRING|"0"
variable=STRING|"var1"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""VAR2"" with value ""{var1(0)}"""
Params=FOLDER

[Actions\Action4\Params]
expand=STRING|"1"
varname=STRING|"VAR2"
varvalue=STRING|"{var1(0)}"

[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|0
Name=STRING|"Set variable ""FILENAME"" with value ""{var2(1)}, {var2(0)} - {var1(1)}"""
Params=FOLDER

[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"FILENAME"
varvalue=STRING|"{var2(1)}, {var2(0)} - {var1(1)}"

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|0
Name=STRING|"Show ""New file name is:"""
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"1"
msg0=STRING|"New file name is:"
msg1=STRING|"{filename}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action7]
ActionID=STRING|"A_FILE_RENAME"
Enabled=INTEGER|-1
Name=STRING|"Rename File"
Params=FOLDER

[Actions\Action7\Params]
count=STRING|"1"
file0=STRING|"{filename}"
mask=STRING|"{var2(1)}, {var2(0)} - {var1(1)}"
subdirs=STRING|"1"

[Actions\Action8]
ActionID=STRING|"A_GENERAL_PAUSE"
Enabled=INTEGER|-1
Name=STRING|"Delay 1000 ms"
Params=FOLDER

[Actions\Action8\Params]
delay=STRING|"10"

[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
Last edited by merle on Fri Oct 05, 2007 3:31 am, edited 1 time in total.
Post Reply