Re: Relative path
Re: Relative path
- Subject: Re: Relative path
- From: Jolly Roger <email@hidden>
- Date: Wed, 20 Dec 2000 14:09:04 -0600
- Replyto: email@hidden
on 12/20/2000 1:40 PM, Matt Sainson wrote:
>
I'm trying to get the path to a file that is relative to the path to the
>
script that is running. I understand the use of "me" however, in tinkering
>
around, I can't seem to get the folder of "me", and subsequently the parent
>
folder of that folder and etc. Is this something that is managed through
>
string manipulation of path names of can it be done with finder commands?
I would use string manipulation; but you can do it in a number of ways.
here's how I would do it:
set myPath to (path to me) as text
set father to ParentFromPath(myPath, true)
set grandpa to ParentFromPath(father, true)
log myPath
log father
log grandpa
on ParentFromPath(thePath, wantPath)
set thePath to (thePath as text)
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set pathAsList to text items of thePath
if the last character of thePath is ":" then
set idx to (the number of text items in thePath) - 2
else
set idx to -2
end if
if wantPath then
set folderName to ((text items 1 through idx of pathAsList) as text)
& ":"
else
set folderName to item idx of pathAsList
end if
set AppleScript's text item delimiters to saveDelim
return folderName
end ParentFromPath
HTH
JR