Path to folder

Hi,
I have a path in POSIX format: for example “/Volumes/Documents/Users/Test/test.sh”.
How can obtain the path of the folder that contains my shell:
“/Volumes/Documents/Users/Test” ?

TIA

Gianni

Hi,

you can coerce a POSIX path to a HFS path with


set POSIXpath to "/Volumes/Documents/Users/Test/test.sh"
set HFSpath to POSIX file POSIXpath as text

If the path is valid, the result will be “Documents:Users:Test:test.sh”
If the path is not valid, the result will be “[startup volume]:Volumes:Documents:Users:Test:test.sh”

You might also find dirname useful.

set p to "/Volumes/Documents/Users/Test/test.sh"
do shell script "dirname " & quoted form of p --> "/Volumes/Documents/Users/Test"

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 4 Public Beta (4528.17)
Operating System: Mac OS X (10.4)

set POSIXpath to "/Volumes/Documents/Users/Test/test.sh"

set AppleScript's text item delimiters to "/"
set iterimValue to text items of POSIXpath
set posixContainerFolder to (items 1 thru -2 of iterimValue) as text
set AppleScript's text item delimiters to ""
return posixContainerFolder

No need to convert to items and back there:

set POSIXpath to "/Volumes/Documents/Users/Test/test.sh"

set AppleScript's text item delimiters to "/"
set posixContainerFolder to text 1 thru text item -2 of POSIXpath
set AppleScript's text item delimiters to ""
return posixContainerFolder

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 4 Public Beta (4528.17)
Operating System: Mac OS X (10.4)