Page 1 of 1

What is the best way to get the filename of full path

Posted: Sat Jan 26, 2013 3:41 pm
by csoca
Hi,
I have a string (full path): website/folder1/folder1/myimage.jpg (String!)
I want to extract the filename "myimage.jpg"

furthermore I need the fileextension "jpg"
thanks for any suggestions and links
Chris

Re: What is the best way to get the filename of full path

Posted: Sat Jan 26, 2013 3:54 pm
by Klaus
Hi Chris,

"the itemdelimiter" (or short "itemdel") is your friend :D

Use it like this:
...
put "website/folder1/folder1/myimage.jpg" into tFullPath

## Filename:
set itemdel to "/"
put item -1 of tFullPath into tFileName
## -> myimage.jpg

## Suffix:
set itemdel to "."
put item -1 of tFileName into tSuffix
## -> jpg
...
Check the dictionary for more info about "itemdelimiter"!


Best

Klaus