Getting files into a Option menu

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
ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm
Location: Netherlands, waardenburg

Getting files into a Option menu

Post by ivaho » Tue Feb 28, 2012 1:28 pm

Hi,

I'am trying to get files from a directory into an Option Menu.

I want to select a file in the option menu and send it to a server.
The sending part is not a problem only the getting the files in the Option menu.

I've read the beginners manual and am able to get the files in a field but not into an Option menu.

Kind regards

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

Re: Getting files into a Option menu

Post by Klaus » Tue Feb 28, 2012 2:37 pm

Hi ivaho,

welcome to the forum! :)

Here some great leraning resources:
http://www.runrev.com/developers/lesson ... nferences/

OK, what did you try so far to "get the files into an option menu"?
You could:
...
put the files into tFiles
set the text of btn "your option menu here" to tFiles
...
OR simply:
...
put tFiles into btn "your option menu here"
...

Is that what you mean?


Best

Klaus

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm
Location: Netherlands, waardenburg

Re: Getting files into a Option menu

Post by ivaho » Sun Mar 04, 2012 12:15 pm

Hi Klaus,

Thanks for your reply.

[put tFiles into btn "your option menu here"] was the solution i was looking for, had no idea i could just put them into the button and the files would appear as choises.

I'am trying to write a simple program for playing files using a server(CasparCG)

Now i have the files in my Option Menu, i would like that the .mp4 or .mov extensions are not visible in the list.
I've read it somewhere on the forum here but cant find it any more.

After that i need to send the following command to the server.

write "play 1 (option menu choice) " & format("\r\n") to socket "localhost:5250"

the command for playing a file on the server onder a normal button is
write "play 1 amb" & format("\r\n") to socket "localhost:5250" where amb is the file on the server.

kind regards
Ivo

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Getting files into a Option menu

Post by kdjanz » Sun Mar 04, 2012 5:07 pm

Since the list of files is just a list of lines of text, you can loop through them and trim the ends off each line in tFiles - before you put that text into your button menu. You can look up working with chunk data if you don't know how to do that - http://lessons.runrev.com/s/lessons/m/4 ... -with-text - might be a good place to start.

Kelly

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

Re: Getting files into a Option menu

Post by Klaus » Sun Mar 04, 2012 5:33 pm

Hi Ivo,

you can use the "filter" command!
...
put the files into tFiles

## "filter without" is our friend :-)
filter tFiles without "*.mp4"
filter tFiles without "*.mov"
...

Done 8)


Best

Klaus

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm
Location: Netherlands, waardenburg

Re: Getting files into a Option menu

Post by ivaho » Tue Mar 06, 2012 5:00 pm

Hi klaus,

If i put

filter listFiles without "*.mp4"
put listFiles(currentFolder(), ) into button "Option Menu"

there are still files showing with .mp4 on the end.

And i think the filter works as that files with extention .mp4 will not be showing, but i want those files to be showing but without the .mp4 extennsion.

I need the files to be displayed without there extension.

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

Re: Getting files into a Option menu

Post by Klaus » Tue Mar 06, 2012 5:48 pm

Hi Ivo,

well, it might be a good idea to FIRST get the files and THEN filter them :D
...
## I think this is your function that gets the files, right?
## Is the COMMA corect in the function call? -> listFiles(currentFolder(), ) ?
put listFiles(currentFolder(), ) into tFiles
filter tFiles without "*.mp4"
put tFiles into button "Option Menu"
...

Best

Klaus

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm
Location: Netherlands, waardenburg

Re: Getting files into a Option menu

Post by ivaho » Thu Mar 15, 2012 7:33 pm

Hi Klaus,

Sorry for the late responce but I wasn't able to check things out.

Your option works but it removes the files with *.mp4 from my list.

What i was looking for was a solution to remove the extension .mp4 or .avi or .???
So basicly remove the last 4 characters

I've got this to work but it works only for the first line

put listFiles(currentFolder(), ) into field "fFiles"
delete char -4 to -1 of word 1 of field "fFiles"

How to go throuh the entire list of files??

Kind regards Ivo

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

Re: Getting files into a Option menu

Post by Klaus » Thu Mar 15, 2012 7:40 pm

Hi Ivo,

ah, you only want to see MP4 files in the menu but without the siffix .mp4, right?
Simply use REPLACE with EMPTY :-)
...
put listFiles(currentFolder(), ) fFiles
filter tFiles with "*.mp4"
replace ".mp4" with EMPTY in tFiles
put tFiles into fld "fFiles"
## or into button...
...

Best

Klaus

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

Re: Getting files into a Option menu

Post by mwieder » Thu Mar 15, 2012 7:42 pm

Any number of ways to do this. Here's one:

Code: Select all

put listFiles(currentFolder(), ) into tFiles
set the itemdelimiter to "."
repeat for each line tFileName in tFiles
  put item 1 of tFileName & cr after field "fFiles"
end repeat
(Klaus - unfortunately the replace command won't replace wildcard templates)

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm
Location: Netherlands, waardenburg

Re: Getting files into a Option menu

Post by ivaho » Thu Mar 15, 2012 7:50 pm

Thank you

Your code was adding the files to the files list but putting

put empty into field "fFiles"

before the code, solved that to for me

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”