Page 1 of 1

get path basename or how to parse a file path

Posted: Tue Apr 30, 2013 8:13 pm
by daryl
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

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

Posted: Tue Apr 30, 2013 8:31 pm
by Dixie
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

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

Posted: Tue Apr 30, 2013 9:13 pm
by mwieder
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".

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

Posted: Tue Apr 30, 2013 9:29 pm
by daryl
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