The technique I'm usually using is this

if the platform.environment contains "windows" then
separator = "/"
else
separator = ":"
end if  
OldDelimiter = the itemdelimiter
the itemdelimiter = separator
filename = the last item of filepath -- assuming filepath contains the whole string
the itemdelimiter = OldDelimiter

no  repeats needed, works like a charm

hth

Bart




On 22 Nov 2005, at 20:54, Mendelsohn, Michael wrote:

is it the # of the last element in a list?

Sorry, Buzz. I should've been clearer. I'm looking for a quick way to take a path (string) and chop it down to just the file name. I came up
with this:

on reduceToFileName(thePath)
  -- chops off all slashes (char 92) and returns just the file name.
  repeat with i = thePath.length down to 1
    if(charToNum(thePath.char[i]) = 92) then
      return thePath.char[(i+1)..(thePath.length)]
      exit repeat
    end if
  end repeat
End

-- example:
fileName = reduceToFileName("C:\Documents and
Settings\currentUser\Desktop\web.html")
put fileName
-- "web.html"

I figured simply getting the last index of the "\" would work easier. I could have sworn that at one time, Tom Higgins posted one line of MX2004
syntax to do this, and I just can't remember what it was, and that
dastardly lingo-L list yields no results.  :-)

Thanks,
- Michael M.


[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [email protected] (Problems, email owner- [email protected]). Lingo-L is for learning and helping with programming Lingo. Thanks!]

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[email protected]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to