ScriptSpot

Forum topic · General Scripting

String manipulation - join

By Dariusz · 2015-07-27

Description

Heya

This is bit annoying but I cant figure it out.

So basically :

str = rendOutputFilename
Divide = filterString str "\\"

This gets me the location where I save images and split the string in to groups.

Now I want to remove the last group which is the name of file so all I will be left with is patch.

how can I now substract that last part and re-join it all so its proper "C:/test/test/test/"

Regards

Dariusz

Comments (1)

barigazy · 2015-07-27

You are asking for this


str = "C:\\SomeFolder\\SomeSubfolder\\image.jpg"
strParts = filterstring str "\\"
newpath = ""
for s = 1 to strParts.count-1 do append newpath (strParts[s]+"/")
newpath

This is wrong way.
This will be one of meny ways but is better from previous for sure

str = "C:\\SomeFolder\\SomeSubfolder\\image.jpg"
filepath = pathConfig.removePathLeaf str
newfilename = pathConfig.appendpath filepath "newimage.png"