getting filename

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
KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

getting filename

Post by KennyR » Fri Apr 18, 2014 2:17 am

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?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: getting filename

Post by Simon » Fri Apr 18, 2014 3:14 am

hmmm....
set itemDel to "/"

???

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm
Location: France

Re: getting filename

Post by atout66 » Fri Apr 18, 2014 10:26 am

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.
Discovering LiveCode Community 6.5.2.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: getting filename

Post by magice » Fri Apr 18, 2014 10:31 am

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

Klaus
Posts: 13854
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: getting filename

Post by Klaus » Fri Apr 18, 2014 11:47 am

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:

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: getting filename

Post by jmburnod » Fri Apr 18, 2014 12:03 pm

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
https://alternatic.ch

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: getting filename

Post by KennyR » Fri Apr 18, 2014 12:22 pm

that's far more help than I ever expected! Thanks to everyone...

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm
Location: France

Re: getting filename

Post by atout66 » Fri Apr 18, 2014 12:47 pm

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.
Discovering LiveCode Community 6.5.2.

Klaus
Posts: 13854
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: getting filename

Post by Klaus » Fri Apr 18, 2014 12:51 pm

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

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: getting filename

Post by magice » Fri Apr 18, 2014 1:16 pm

Klaus wrote: :shock: :shock: :shock:
Not subtle enough?

Klaus
Posts: 13854
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: getting filename

Post by Klaus » Fri Apr 18, 2014 1:30 pm

magice wrote:
Klaus wrote: :shock: :shock: :shock:
Not subtle enough?
A bit cumbersome, to say the least... :D

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm
Location: France

Re: getting filename

Post by atout66 » Fri Apr 18, 2014 2:14 pm

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:
Discovering LiveCode Community 6.5.2.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”