rename file on base of foldername

Discuss RoboTask here
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: rename file on base of foldername

Post by Oleg »

See my folder structure:
folderstruct.png
folderstruct.png (44.78 KiB) Viewed 17671 times
The task makes the loop in the folder D:\Temp\images with subfolders (see step #5)

This task renames all files in subfolders with your rule.

Now this folder with subfolders such:

Code: Select all

 Volume in drive D is old_system
 Volume Serial Number is CC50-B66A

 Directory of D:\Temp\images

25.07.2014  15:48    <DIR>          .
25.07.2014  15:48    <DIR>          ..
25.07.2014  15:48                 0 111
25.07.2014  15:43    <DIR>          18658-266.10.288
25.07.2014  15:43    <DIR>          18765-266.10.288
25.07.2014  15:43    <DIR>          18765-266.10.300
25.07.2014  15:06    <DIR>          18765-266.10.301
               1 File(s)              0 bytes

 Directory of D:\Temp\images\18658-266.10.288

25.07.2014  15:43    <DIR>          .
25.07.2014  15:43    <DIR>          ..
25.07.2014  15:44    <DIR>          images2d
               0 File(s)              0 bytes

 Directory of D:\Temp\images\18658-266.10.288\images2d

25.07.2014  15:44    <DIR>          .
25.07.2014  15:44    <DIR>          ..
25.07.2014  13:15                 0 18658-266.10.288-0001.jpg
25.07.2014  13:15                 0 18658-266.10.288-0002.jpg
25.07.2014  13:15                 0 18658-266.10.288-0003.jpg
25.07.2014  13:15                 0 18658-266.10.288-0004.jpg
25.07.2014  13:15                 0 18658-266.10.288-0005.jpg
               5 File(s)              0 bytes

 Directory of D:\Temp\images\18765-266.10.288

25.07.2014  15:43    <DIR>          .
25.07.2014  15:43    <DIR>          ..
25.07.2014  15:44    <DIR>          images2d
               0 File(s)              0 bytes

 Directory of D:\Temp\images\18765-266.10.288\images2d

25.07.2014  15:44    <DIR>          .
25.07.2014  15:44    <DIR>          ..
25.07.2014  13:15                 0 18765-266.10.288-0001.jpg
25.07.2014  13:15                 0 18765-266.10.288-0002.jpg
25.07.2014  13:15                 0 18765-266.10.288-0003.jpg
25.07.2014  13:15                 0 18765-266.10.288-0004.jpg
25.07.2014  13:15                 0 18765-266.10.288-0005.jpg
               5 File(s)              0 bytes

 Directory of D:\Temp\images\18765-266.10.300

25.07.2014  15:43    <DIR>          .
25.07.2014  15:43    <DIR>          ..
25.07.2014  15:44    <DIR>          images2d
               0 File(s)              0 bytes

 Directory of D:\Temp\images\18765-266.10.300\images2d

25.07.2014  15:44    <DIR>          .
25.07.2014  15:44    <DIR>          ..
25.07.2014  13:15                 0 18765-266.10.300-0001.jpg
25.07.2014  13:15                 0 18765-266.10.300-0002.jpg
25.07.2014  13:15                 0 18765-266.10.300-0003.jpg
25.07.2014  13:15                 0 18765-266.10.300-0004.jpg
25.07.2014  13:15                 0 18765-266.10.300-0005.jpg
               5 File(s)              0 bytes

 Directory of D:\Temp\images\18765-266.10.301

25.07.2014  15:06    <DIR>          .
25.07.2014  15:06    <DIR>          ..
25.07.2014  15:44    <DIR>          images2d
               0 File(s)              0 bytes

 Directory of D:\Temp\images\18765-266.10.301\images2d

25.07.2014  15:44    <DIR>          .
25.07.2014  15:44    <DIR>          ..
25.07.2014  13:15                 0 18765-266.10.301-0001.jpg
25.07.2014  13:15                 0 18765-266.10.301-0002.jpg
25.07.2014  13:15                 0 18765-266.10.301-0003.jpg
25.07.2014  13:15                 0 18765-266.10.301-0004.jpg
25.07.2014  13:15                 0 18765-266.10.301-0005.jpg
               5 File(s)              0 bytes

Oleg Yershov
rice1973
Posts: 86
Joined: Mon Jan 04, 2010 2:38 am
Location: Netherlands
Contact:

Re: rename file on base of foldername

Post by rice1973 »

Hi,

New "litle problem"

The subfolder in C:\3dmap\18765-266.10.300 are

images
images2d
thumbnails

They all have content. Only the images in the folder images2d have to be renamed.

I tried a few solutions in line 6 ( {ExtractFileName({ExtractFilePath({ExtractFilePath({FileName})})})} )

But i can't get it working properly.
Robotask rules! :)
rice1973
Posts: 86
Joined: Mon Jan 04, 2010 2:38 am
Location: Netherlands
Contact:

Re: rename file on base of foldername

Post by rice1973 »

Hi Oleg,

Any solution? I am stuck now...
Robotask rules! :)
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: rename file on base of foldername

Post by Oleg »

See the task 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 (only images2d)"
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
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=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_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FILE"" with value ""{ExtractFileName({FileName})}"""
Params=FOLDER

[Actions\Action10\Params]
expand=STRING|"1"
varname=STRING|"FILE"
varvalue=STRING|"{ExtractFileName({FileName})}"

[Actions\Action11]
ActionID=STRING|"A_STR_REPLACE"
Enabled=INTEGER|-1
Name=STRING|"STR Replace"
Params=FOLDER

[Actions\Action11\Params]
case=STRING|"0"
mode=STRING|"0"
replacement=STRING|"{folder}-"
source=STRING|"{file}"
substring=STRING|"img_"
variable=STRING|"NewFile"

[Actions\Action12]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|0
Name=STRING|"Show ""{FileName}"""
Params=FOLDER

[Actions\Action12\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"

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

[Actions\Action13\Params]
count=STRING|"1"
file0=STRING|"{FileName}"
ifexists=STRING|"1"
mask=STRING|"{NewFile}"
subdirs=STRING|"0"

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

[Actions\Action15]
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_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""PARENT"" with value """""
Params=FOLDER

[Actions\Action5\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"PARENT"

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

[Actions\Action6\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\Action7]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""PARENT"" with value ""{ExtractFileName({ExtractFilePath({FileName})})}"""
Params=FOLDER

[Actions\Action7\Params]
expand=STRING|"1"
varname=STRING|"PARENT"
varvalue=STRING|"{ExtractFileName({ExtractFilePath({FileName})})}"

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

[Actions\Action8\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"0"
value1=STRING|"{parent}"
value2=STRING|"images2d"

[Actions\Action9]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FOLDER"" with value ""{ExtractFileName({ExtractFilePath({ExtractFilePath..."""
Params=FOLDER

[Actions\Action9\Params]
expand=STRING|"1"
varname=STRING|"FOLDER"
varvalue=STRING|"{ExtractFileName({ExtractFilePath({ExtractFilePath({FileName})})})}"
I added calculation of parent folder of the file (step #7) and the condition (step #8)
I tested it. It works.
Oleg Yershov
rice1973
Posts: 86
Joined: Mon Jan 04, 2010 2:38 am
Location: Netherlands
Contact:

Re: rename file on base of foldername

Post by rice1973 »

Thanks!
Robotask rules! :)
Post Reply