home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!van-bc!rsoft!mindlink!a347
- From: John_Miller@mindlink.bc.ca (John Miller)
- Newsgroups: comp.sys.mac.hypercard
- Subject: Re: HELP finding the pathname of your stack!
- Message-ID: <14619@mindlink.bc.ca>
- Date: 27 Aug 92 00:55:09 GMT
- Organization: MIND LINK! - British Columbia, Canada
- Distribution: world
- Lines: 128
-
- > I ran into a problem that seems SOOOO very simple, but for the
- > life of me I cannot find an XCMD or XFCN that does it, nor a
- > HyperTalk command that does it. What I NEED to do, is to get the
- > path of the directory that my stack is in. I need to display some
- > PICT files that are in a folder in the directory that the stack is
- > in. So what I want to do is get the directory the stack is in and
- > then just & ":Ads:" to it... but alas, I cannot get the
- > directory my stack is in. I have looked through F Rinaldis
- > XCMDs and XFCNs (a wonderful resource btw) but nothing there will do it.
-
- This question and its cousins have been coming up a lot lately,
- so here are a set of simple functions for getting the current
- stack's full pathname and the folder that contains the current
- stack. As an added bonus, included is a function that will
- return a full pathname for a file starting with either a full
- pathname or a partial pathname.
-
- _____________________________________________________________________
- function stackPathname
- -- Returns the full pathname of the current stack
- get the long name of this stack
- delete word 1 of it
- delete first character of it
- delete last character of it
- return it
- end stackPathname
-
- -----------------------------------------------------------
- -- We have a special on stackFolder functions today: 3 for
- -- the price of 1. Choose the one that you prefer. Version
- -- 3 is probably the best as it should on all file systems
- -- and under all HyperCard versions. (Although if HyperCard
- -- always uses ":" when generating full pathnames, the
- -- issue is moot.)
- -------------------------------------------------------------'
-
- function stackFolder
- -- Returns the path to the folder containing the current stack
- -- Note: I don't know how this version works with
- -- foreign file systems, such as A/UX: will the
- -- stack name be returned with ":" or "/" as
- -- directory separators?
-
- -- Version 1: works with all HyperCard versions
- get stackPathname()
- repeat while last character of it is not ":"
- delete last char of it
- end repeat
- return it
- end stackFolder
-
- function stackFolder
- -- Returns the path to the folder containing the current stack
- -- Note: I don't know how this version works with
- -- foreign file systems, such as A/UX: will the
- -- stack name be returned with ":" or "/" as
- -- directory separators?
-
- -- Version 2: requires new (in HC 2.1) itemDelimiter property
- put the itemDelimiter into saveDelim
- set the itemDelimiter to ":"
- put stackPathname() into pathname
- delete last item of pathname
- set the itemDelimiter to saveDelim
- return pathname & ":" -- oops, have to put the last colon back
- end stackFolder
-
-
- function stackFolder
- -- Returns the path to the folder containing the current stack
-
- -- Version 3: should work even if foreign file systems
- -- use something other than ":" to separate folders in the path
-
- put the length of the short name of this stack into shortLength
- put stackPathname() into fullPath
- put the length of fullPath into longLength
- return char 1 to (longLength - shortLength) of fullPath
- end stackFolder
- ---------------------------------------------------------------------
-
- function fullFilename fname
- -- If fname is a full pathname, this function will return
- -- fname unchanged. If fname is a partial pathname, this
- -- function will return a full pathname by assuming that
- -- fname specifies a path from the folder containing the
- -- current stack.
-
- put stackFolder() into thisFolder
- if first char of fname is ":" then
-
- -- Name starting with a colon is always a partial pathname.
- -- The folder will already have a colon at the end, so we
- -- must get rid of the first colon in fname.
- put thisFolder & (char 2 to 2000 of fname) into pathName
-
-
- else if offset(":", fname) is not 0 then
-
- -- Name that has a colon (but not as the first character)
- -- is a full pathname.
- put fname into pathName
-
- else
-
- -- No colon at all means a file in the same directory as the stack.
- put thisFolder & fname into pathName
- end if
-
- return pathName
-
- -- Alternate approach left as exercise to the reader: if
- -- the file cannot be found by following the path starting at
- -- the current stack's folder, scan through HyperCard's Documents
- -- "search for" list, trying to find the file.
- end fullFilename
-
-
-
-
-
- __________________________________________________________________
-
-
- John Miller
- Symplex Systems
-
-
-