Combining 3 separate paths to make 1 single path

Hi everyone

Combing one or two scripts works fine but when I add a third or forth to the mix, it stops.

the following script works


set ProjectsFolderName to "Projects" -- The name of the folder where you're keeping your projects
set CodeFolderName to "Code" -- The name of the folder where you're keeping your Website Code
set bbbFolderName to "bbb" -- The name of the folder where you're keeping your Website Code

set CurrentPath to POSIX path of CurrentDir
display dialog CurrentPath

Return path is: /Users/User/Documents/Clients/aaa/Projects/

This one also works


set ProjectsFolderName to "Projects" -- The name of the folder where you're keeping your projects
set CodeFolderName to "Code" -- The name of the folder where you're keeping your Website Code
set bbbFolderName to "bbb" -- The name of the folder where you're keeping your Website Code

set CodePath to POSIX path of CurrentDir & CodeFolderName
display dialog CodePath

Return path is: /Users/daniel/Documents/Clients/aaa/Projects/Code

But this one doesn’t


set ProjectsFolderName to "Projects" -- The name of the folder where you're keeping your projects
set CodeFolderName to "Code" -- The name of the folder where you're keeping your Website Code
set bbbFolderName to "bbb" -- The name of the folder where you're keeping your Website Code

set CodePath to POSIX path of CurrentDir & CodeFolderName
display dialog CodePath

Return path is: /Users/daniel/Documents/Clients/aaa/Projects/bbbCode

Why is this and how can I get around it?

OK,

So after trial and error I managed to do the following that seems to work:



-- GET PROJECTS FOLDER PATH
set CurrentPath to quoted form of POSIX path of CurrentDir
display dialog CurrentPath

-- GET PROJECTS FOLDER PATH
set CodePath to quoted form of (POSIX path of CurrentDir & CodeFolderName)
display dialog CodePath

-- GET PROJECTS FOLDER PATH
set bbbPath to quoted form of (POSIX path of CurrentDir & bbbFolderName & (POSIX path of CodeFolderName))
display dialog bbbPath

-- GET PROJECTS FOLDER PATH
set cccPath to quoted form of (POSIX path of CurrentDir & bbbFolderName & (POSIX path of CodeFolderName & (POSIX path of cccFolderName)))
display dialog cccPath

POSIX path of "TEXT" is "/" & "TEXT"
--> RESULT: true
POSIX path of (path to "down") is "/" & "down"
--> RESULT: false

Are you sure that its’ really the posted script which inserted bbb wrongly ?

I assume that you coded :

set CodePath to POSIX path of CurrentDir & bbbFolderName & CodeFolderName

This ask the code to build the POSIX Path of CurrentDir which is supposed to be the string
“/Users/User/Documents/Clients/aaa/Projects/”
then execute

set CodePath to "/Users/User/Documents/Clients/aaa/Projects/"  &  "bbb" & "Code"

You missed the levels separator between the two last components.

Try with :

set CodePath to POSIX path of CurrentDir & bbbFolderName & "/" & CodeFolderName

This time the instruction tells correctly to the script that CodeFolderName is a subfolder of the folder bbbFolderName.

You were fooled because CurrentDir returns a path with a final levels separator available:
“Macintosh HD:Users:User:Documents:Clients:aaa:Projects:” so you didn’t have to insert it or the first sublevel but it’s your duty to insert the next one.

On my side I never use such syntax.
I use:

set CodePath to POSIX path of ((currentDir as text) & bbbFolderName & ":" & CodeFolderName & ":")

This way I build paths with consistent structure, the final level separator is always available at the end of the path of a folder.

An other way which I use now most of the time is to work with ASObjC which is fair enough to insert automatically the separator(s) when it’s urged to build a complete path.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 9 avril 2020 16:38:44