Page 1 of 1

getting filename

Posted: Fri Apr 18, 2014 2:17 am
by KennyR
I am having issues trying to get the filename of the chosen file when I do this...

on mouseUp
answer file "Please choose a file"
answer it
end mouseUp

I know this will give me the full file path, but I want to know how to JUST get the name of the file the user chose. Normally, I would just put the file path in a variable then strip away all the words prior to the last word, but I can't seem to figure that one out...anyhow, I just want the file name the user chose....ideas?

Re: getting filename

Posted: Fri Apr 18, 2014 3:14 am
by Simon
hmmm....
set itemDel to "/"

???

Simon

Re: getting filename

Posted: Fri Apr 18, 2014 10:26 am
by atout66
Yes, try this:

Code: Select all

on mouseUp
answer file "Please choose a file"
put IT into thePath
set the itemDelimiter to "\"
get last item of thePath
answer IT
end mouseUp
Just an idea...

Kind regards, Jean-Paul.

Re: getting filename

Posted: Fri Apr 18, 2014 10:31 am
by magice
on mouseUp
answer file "Please choose a file"
put it into tFilename
repeat while tFilename contains "/"
delete the first character of tFilename
end repeat
answer tFilename
end mouseUp

Re: getting filename

Posted: Fri Apr 18, 2014 11:47 am
by Klaus
magice wrote:on mouseUp
answer file "Please choose a file"
put it into tFilename
repeat while tFilename contains "/"
delete the first character of tFilename
end repeat
answer tFilename
end mouseUp
:shock: :shock: :shock:

Re: getting filename

Posted: Fri Apr 18, 2014 12:03 pm
by jmburnod
Hi Jean-Paul,

Code: Select all

on mouseUp
   answer file "Please choose a file"
   if it = empty then exit mouseup
   set the itemDelimiter to "/"
   answer item-1 of it
end mouseUp

Re: getting filename

Posted: Fri Apr 18, 2014 12:22 pm
by KennyR
that's far more help than I ever expected! Thanks to everyone...

Re: getting filename

Posted: Fri Apr 18, 2014 12:47 pm
by atout66
jmburnod wrote:Hi Jean-Paul,

Code: Select all

on mouseUp
   answer file "Please choose a file"
   if it = empty then exit mouseup
   set the itemDelimiter to "/"
   answer item-1 of it
end mouseUp
I like your <item-1 of IT> :wink:
But be aware with the itemDelimiter... This one "\" or not this one "/", that is the question :!: :?: :)
Kind regards, Jean-Paul.

Re: getting filename

Posted: Fri Apr 18, 2014 12:51 pm
by Klaus
Hi friends,
This one "\" or not this one "/", that is the question
whatever platform you are on, Livecode will internally ALWAYS (sic!) use the UNIX Slash / as a path delimiter!

Happy easter :D


Best

Klaus

Re: getting filename

Posted: Fri Apr 18, 2014 1:16 pm
by magice
Klaus wrote: :shock: :shock: :shock:
Not subtle enough?

Re: getting filename

Posted: Fri Apr 18, 2014 1:30 pm
by Klaus
magice wrote:
Klaus wrote: :shock: :shock: :shock:
Not subtle enough?
A bit cumbersome, to say the least... :D

Re: getting filename

Posted: Fri Apr 18, 2014 2:14 pm
by atout66
whatever platform you are on, Livecode will internally ALWAYS (sic!) use the UNIX Slash / as a path delimiter!
Aaah, this LC is so cleaver... :roll: