Page 1 of 2
rename file on base of foldername
Posted: Fri Jul 25, 2014 10:03 am
by rice1973
Hi Oleg,
I need to rename a fil in a folder with a prefix of the foldername.
Example;
foldername :
18765-266.10.300
files in the folder;
img_0001.jpg
img_0002.jpg
img_0003.jpg
img_0004.jpg
img_0005.jpg
New name of files must be;
18765-266.10.300-001.jpg
18765-266.10.300-002.jpg
18765-266.10.300-003.jpg
18765-266.10.300-004.jpg
18765-266.10.300-005.jpg
I cannot get the name extracted form the foldername and past it as prefix .
Can you help?
Regards,
Maurice
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 11:15 am
by rice1973
For info;
There is only one map in the folder (every time it has another name)
I tried to work with;
{ExtractFilePath(C:\Folder\File.ext)} Cannot get it working.
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 11:28 am
by Oleg
Look at my example below
Pay attention onto step #6
use the expression
{ExtractFileName({ExtractFilePath({filename})})}
In other words you need extract
file part from
full path of the file
Code: Select all
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|317955339
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task372"
Hide=INTEGER|0
ID=INTEGER|1259557504
LogOnAsUser=INTEGER|1
Name=STRING|"Extract folder"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FILENAME"" with value """""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FILENAME"
[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""NAMEONLY"" with value """""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"NAMEONLY"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FOLDER"" with value """""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FOLDER"
[Actions\Action4]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER
[Actions\Action4\Params]
createmode=STRING|"1"
date1=STRING|"20140725"
date2=STRING|"20140725"
destvar=STRING|"FILENAME"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"d:\temp\images\*.jpg"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
sort=STRING|"0"
sortby=STRING|"0"
sortorder=STRING|"0"
subdirs=STRING|"1"
timesize=STRING|"0"
WithoutPath=STRING|"0"
[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""NAMEONLY"" with value ""{ExtractFileName({filename})}"""
Params=FOLDER
[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"NAMEONLY"
varvalue=STRING|"{ExtractFileName({filename})}"
[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FOLDER"" with value ""{ExtractFileName({ExtractFilePath({filename})})}"""
Params=FOLDER
[Actions\Action6\Params]
expand=STRING|"1"
varname=STRING|"FOLDER"
varvalue=STRING|"{ExtractFileName({ExtractFilePath({filename})})}"
[Actions\Action7]
ActionID=STRING|"A_ROBOTASK_ALERT"
Enabled=INTEGER|-1
Name=STRING|"Show Notification"
Params=FOLDER
[Actions\Action7\Params]
defh=STRING|"0"
defw=STRING|"0"
duration=STRING|"10"
height=STRING|"100"
icon=STRING|"3"
kind=STRING|"0"
message=STRING|"{filename}{chr(10)}File={Nameonly}{chr(10)}Folder={folder}"
position=STRING|"3"
title=STRING|"File info"
width=STRING|"400"
[Actions\Action8]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 11:54 am
by rice1973
Hi Oleg,
Sorry my explenation was not enough i see. I will explain a bit better .
The folder/file structure is like this;
C:\3dmap\18658-266.10.288\images2d\img_0001.jpg
The file has to be renamed to;
C:\3dmap\18658-266.10.288\images2d\18658-266.10.288-0001.jpg
The foldername now containing 18658-266.10.288 is different each time.
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 12:11 pm
by Oleg
in tis case try this expression:
{ExtractFileName({ExtractFilePath({ExtractFilePath({FileName})})})}
Variable
FileName should contain the full path of the file.
See the example (step #5):
Code: Select all
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|317955339
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task373"
Hide=INTEGER|0
ID=INTEGER|234316423
LogOnAsUser=INTEGER|1
Name=STRING|"File name transformation"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FILENAME"" with value ""C:\3dmap\18658-266.10.288\images2d\img_0001.jpg"""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FILENAME"
varvalue=STRING|"C:\3dmap\18658-266.10.288\images2d\img_0001.jpg"
[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FILE"" with value """""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FILE"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FOLDER"" with value """""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FOLDER"
[Actions\Action4]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""NEWFILE"" with value """""
Params=FOLDER
[Actions\Action4\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"NEWFILE"
[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FOLDER"" with value ""{ExtractFileName({ExtractFilePath({ExtractFilePath..."""
Params=FOLDER
[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"FOLDER"
varvalue=STRING|"{ExtractFileName({ExtractFilePath({ExtractFilePath({FileName})})})}"
[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FILE"" with value ""{ExtractFileName({FileName})}"""
Params=FOLDER
[Actions\Action6\Params]
expand=STRING|"1"
varname=STRING|"FILE"
varvalue=STRING|"{ExtractFileName({FileName})}"
[Actions\Action7]
ActionID=STRING|"A_STR_REPLACE"
Enabled=INTEGER|-1
Name=STRING|"STR Replace"
Params=FOLDER
[Actions\Action7\Params]
case=STRING|"0"
mode=STRING|"0"
replacement=STRING|"{folder}-"
source=STRING|"{file}"
substring=STRING|"img_"
variable=STRING|"NewFile"
[Actions\Action8]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{FileName}"""
Params=FOLDER
[Actions\Action8\Params]
icon=STRING|"1"
msg0=STRING|"{FileName}"
msg1=STRING|"{File}"
msg2=STRING|"{Folder}"
msg3=STRING|"{NewFile}"
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 12:24 pm
by rice1973
Hi,
I run the task, in the attachment the display message. But there is no filename changed...?
And is it possible to "read" the variable filename form the path? so the number "18658-266.10.288" because that is evertime different.
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 12:45 pm
by Oleg
1-st line the source filename
2-nd file name only
3-d - the necessary folder name
4-th - new file name
Look at the task in the task editor.
You can set to vatiable FileName any new full path of the file and the task will parse it.
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 12:48 pm
by rice1973
I understand that.
But it does not rename the file in the folder.
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 1:13 pm
by Oleg
See example below:
Code: Select all
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|317955339
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task372"
Hide=INTEGER|0
ID=INTEGER|1259557504
LogOnAsUser=INTEGER|1
Name=STRING|"Rename files"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
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_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FILENAME"" with value """""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FILENAME"
[Actions\Action10]
ActionID=STRING|"A_FILE_RENAME"
Enabled=INTEGER|-1
Name=STRING|"Rename File"
Params=FOLDER
[Actions\Action10\Params]
count=STRING|"1"
file0=STRING|"{FileName}"
ifexists=STRING|"1"
mask=STRING|"{NewFile}"
subdirs=STRING|"0"
[Actions\Action11]
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 local variable ""FILE"" with value """""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FILE"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FOLDER"" with value """""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FOLDER"
[Actions\Action4]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""NEWFILE"" with value """""
Params=FOLDER
[Actions\Action4\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"NEWFILE"
[Actions\Action5]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER
[Actions\Action5\Params]
createmode=STRING|"1"
date1=STRING|"20140725"
date2=STRING|"20140725"
destvar=STRING|"FILENAME"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"d:\temp\images\*.jpg"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
sort=STRING|"0"
sortby=STRING|"0"
sortorder=STRING|"0"
subdirs=STRING|"1"
timesize=STRING|"0"
WithoutPath=STRING|"0"
[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FOLDER"" with value ""{ExtractFileName({ExtractFilePath({ExtractFilePath..."""
Params=FOLDER
[Actions\Action6\Params]
expand=STRING|"1"
varname=STRING|"FOLDER"
varvalue=STRING|"{ExtractFileName({ExtractFilePath({ExtractFilePath({FileName})})})}"
[Actions\Action7]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FILE"" with value ""{ExtractFileName({FileName})}"""
Params=FOLDER
[Actions\Action7\Params]
expand=STRING|"1"
varname=STRING|"FILE"
varvalue=STRING|"{ExtractFileName({FileName})}"
[Actions\Action8]
ActionID=STRING|"A_STR_REPLACE"
Enabled=INTEGER|-1
Name=STRING|"STR Replace"
Params=FOLDER
[Actions\Action8\Params]
case=STRING|"0"
mode=STRING|"0"
replacement=STRING|"{folder}-"
source=STRING|"{file}"
substring=STRING|"img_"
variable=STRING|"NewFile"
[Actions\Action9]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|0
Name=STRING|"Show ""{FileName}"""
Params=FOLDER
[Actions\Action9\Params]
icon=STRING|"1"
msg0=STRING|"{FileName}"
msg1=STRING|"{File}"
msg2=STRING|"{Folder}"
msg3=STRING|"{NewFile}"
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"
It works. I tested it on the folder:
D:\Temp\images\18765-266.10.300\images2d\
this folder contain files:
img_0001.jpg
img_0002.jpg
img_0003.jpg
img_0004.jpg
img_0005.jpg
After running the task:
18765-266.10.300-0001.jpg
18765-266.10.300-0002.jpg
18765-266.10.300-0003.jpg
18765-266.10.300-0004.jpg
18765-266.10.300-0005.jpg
Re: rename file on base of foldername
Posted: Fri Jul 25, 2014 1:22 pm
by rice1973
Hi,
I almost had the solution.
Works fine.
But now i need the number
18658-266.10.288 ( in line 5 "File Loop") as a variable, so it has to be read from the foldername. Because everytime it runs it is a different number.
I cannot get that working
