• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Relative path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Relative path (From: Matt Sainson <email@hidden>)

  • Prev by Date: Re: "11/31/99" to date
  • Next by Date: Re: easy way to check if item is file or folder
  • Previous by thread: Relative path
  • Next by thread: Re: Relative path
  • Index(es):
    • Date
    • Thread