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

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
csoca
Posts: 4
Joined: Fri Jan 18, 2013 7:39 pm

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

Post by csoca » Sat Jan 26, 2013 3:41 pm

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

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

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

Post by Klaus » Sat Jan 26, 2013 3:54 pm

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

Post Reply