news
About Elegant Chaos
info
About me and my friends
people
Software from Elegant Chaos
software
Other stuff...
stuff

FL_FolderFromPath

Revision
Revised on

Description

Return the pathname of the folder that a file is in. Takes the full pathname of the file.

If passed a folder name (with or without a colon on the end), it returns the parent folder of the folder.

Note that this routine doesn't check to see whether the file/folder exists or whether the path is legal.


Code

function FL_FolderFromPath path
  -- given the path to a file, returns the folder that the file is in
  
  -- if the last character is a colon, get rid of it first
  if the last char of path is colon then
    delete last char of path
  end if
  
  -- set the item delimiter to colon instead of comma
  get the itemDelimiter
  set the itemDelimiter to colon
  
  -- take off stuff after (and including) last colon
  delete last item of path
  set the itemDelimiter to it
  put colon after path
  
  -- send back the result
  return path
end FL_FolderFromPath