home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / hypercar / 3268 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  4.7 KB

  1. Path: sparky!uunet!van-bc!rsoft!mindlink!a347
  2. From: John_Miller@mindlink.bc.ca (John Miller)
  3. Newsgroups: comp.sys.mac.hypercard
  4. Subject: Re:  HELP finding the pathname of your stack!
  5. Message-ID: <14619@mindlink.bc.ca>
  6. Date: 27 Aug 92 00:55:09 GMT
  7. Organization: MIND LINK! - British Columbia, Canada
  8. Distribution: world
  9. Lines: 128
  10.  
  11. > I ran into a problem that seems SOOOO very simple, but for the
  12. > life of me I cannot find an XCMD or XFCN that does it, nor a
  13. > HyperTalk command that does it. What I NEED to do, is to get the
  14. > path of the directory that my stack is in.  I need to display some
  15. > PICT files that are in a folder in the directory that the stack is
  16. > in. So what I want to do is get the directory the stack is in and
  17. > then just & ":Ads:" to it... but alas, I cannot get the
  18. > directory my stack is in. I have looked through F Rinaldis
  19. > XCMDs and XFCNs (a wonderful resource btw) but nothing there will do it.
  20.  
  21. This question and its cousins have been coming up a lot lately,
  22. so here are a set of simple functions for getting the current
  23. stack's full pathname and the folder that contains the current
  24. stack.  As an added bonus, included is a function that will
  25. return a full pathname for a file starting with either a full
  26. pathname or a partial pathname.
  27.  
  28. _____________________________________________________________________
  29. function stackPathname
  30.   -- Returns the full pathname of the current stack
  31.   get the long name of this stack
  32.   delete word 1 of it
  33.   delete first character of it
  34.   delete last character of it
  35.   return it
  36. end stackPathname
  37.  
  38. -----------------------------------------------------------
  39. -- We have a special on stackFolder functions today: 3 for
  40. -- the price of 1.  Choose the one that you prefer.  Version
  41. -- 3 is probably the best as it should on all file systems
  42. -- and under all HyperCard versions.  (Although if HyperCard
  43. -- always uses ":" when generating full pathnames, the
  44. -- issue is moot.)
  45. -------------------------------------------------------------'
  46.  
  47. function stackFolder
  48.   -- Returns the path to the folder containing the current stack
  49.   -- Note:  I don't know how this version works with
  50.   -- foreign file systems, such as A/UX:  will the
  51.   -- stack name be returned with ":" or "/" as
  52.   -- directory separators?
  53.  
  54.   -- Version 1: works with all HyperCard versions
  55.   get stackPathname()
  56.   repeat while last character of it is not ":"
  57.     delete last char of it
  58.   end repeat
  59.   return it
  60. end stackFolder
  61.  
  62. function stackFolder
  63.   -- Returns the path to the folder containing the current stack
  64.   -- Note:  I don't know how this version works with
  65.   -- foreign file systems, such as A/UX:  will the
  66.   -- stack name be returned with ":" or "/" as
  67.   -- directory separators?
  68.  
  69.   -- Version 2: requires new (in HC 2.1) itemDelimiter property
  70.   put the itemDelimiter into saveDelim
  71.   set the itemDelimiter to ":"
  72.   put stackPathname() into pathname
  73.   delete last item of pathname
  74.   set the itemDelimiter to saveDelim
  75.   return pathname & ":" -- oops, have to put the last colon back
  76. end stackFolder
  77.  
  78.  
  79. function stackFolder
  80.   -- Returns the path to the folder containing the current stack
  81.  
  82.   -- Version 3: should work even if foreign file systems
  83.   -- use something other than ":" to separate folders in the path
  84.  
  85.   put the length of the short name of this stack into shortLength
  86.   put stackPathname() into fullPath
  87.   put the length of fullPath into longLength
  88.   return char 1 to (longLength - shortLength) of fullPath
  89. end stackFolder
  90. ---------------------------------------------------------------------
  91.  
  92. function fullFilename fname
  93.   -- If fname is a full pathname, this function will return
  94.   -- fname unchanged.  If fname is a partial pathname, this
  95.   -- function will return a full pathname by assuming that
  96.   -- fname specifies a path from the folder containing the
  97.   -- current stack.
  98.  
  99.   put stackFolder() into thisFolder
  100.   if first char of fname is ":" then
  101.  
  102.     -- Name starting with a colon is always a partial pathname.
  103.     -- The folder will already have a colon at the end, so we
  104.     -- must get rid of the first colon in fname.
  105.     put thisFolder & (char 2 to 2000 of fname) into pathName
  106.  
  107.  
  108.   else if offset(":", fname) is not 0 then
  109.  
  110.     -- Name that has a colon (but not as the first character)
  111.     -- is a full pathname.
  112.     put fname into pathName
  113.  
  114.   else
  115.  
  116.     -- No colon at all means a file in the same directory as the stack.
  117.     put thisFolder & fname into pathName
  118.   end if
  119.  
  120.   return pathName
  121.  
  122.   -- Alternate approach left as exercise to the reader:  if
  123.   -- the file cannot be found by following the path starting at
  124.   -- the current stack's folder, scan through HyperCard's Documents
  125.   -- "search for" list, trying to find the file.
  126. end fullFilename
  127.  
  128.  
  129.  
  130.  
  131.  
  132. __________________________________________________________________
  133.  
  134.  
  135. John Miller
  136. Symplex Systems
  137.  
  138.  
  139.