get path basename or how to parse a file 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
daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

get path basename or how to parse a file path

Post by daryl » Tue Apr 30, 2013 8:13 pm

Hi Folks,

I am very new to LiveCode, but trying to get up to speed quickly. Right now I am stuck trying to parse a file path, so given the following file path:

/some/foo/bar/path/to/bingo.html

how can I put the filename bingo.html into a container? I have searched and searched without success. It seems to be more complicated than it needs to be.

Any help or pointers to documentation would be greatly appreciated.

Thanks,

Daryl

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: get path basename or how to parse a file path

Post by Dixie » Tue Apr 30, 2013 8:31 pm

Hi..

Code: Select all

set itemDel to slash
put "/some/foo/bar/path/to/bingo.html" into theString
put the last item of theString
will put 'bingo.html' into the msg box

Dixie

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: get path basename or how to parse a file path

Post by mwieder » Tue Apr 30, 2013 9:13 pm

Another useful trick to know is that

Code: Select all

put item 1 to -2 of theString
will give you the enclosing folder of bingo.html, i.e., "/some/foo/bar/path/to".

daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

Re: get path basename or how to parse a file path

Post by daryl » Tue Apr 30, 2013 9:29 pm

Wow! That was fast and very useful. Thank you both, Dixie and mwieder for your suggestions, I appreciate both of your responses, and they will prove very useful to me.

Best Regards,

Daryl

Post Reply