I have an idea for a new movie widget. It's based on the photo widget but instead of showing one picture at a time it would show a 5x4 grid of pictures. When you click the picture inside the box it would open the movie directly (the same as if you double click the file from windows explorer).

The reason for this widget is so my 5 year old niece can select a movie from my library without needing the ability to read the file name (over 200 movies).

The problem is that I don't know lua script and I'm just guessing.

First, how do I find out if a table entry exists in a second table?

Table A is created from a folder that consists only of movies but with different extensions. Example Table A:
Finding Nemo.avi
Ice Age.flv
Shrek.mp4
The Little Mermaid.mpg
The Wizard of Oz.mkv

Table B is created from a folder that consists only of pictures but with different extensions. Example Table B:
Finding Nemo.bmp
Shrek.jpg
The Little Mermaid.gif
The Wizard of Oz.png
Picture Not Found.jpg

If my result from table A is Shrek.mp4, how do I write the script code to find out if it is listed in table B and then extract the correct file name which should be Shrek.jpg? (If the file is not there - example: Ice Age.flv - it should default to Picture Not Found.jpg).

I will then have 2 urls, one for the picture preview and one to execute the movie. This will be done for every entry in table A.

I have been googling Lua manuals for days now but I cannot seem to understand how to apply what I read to my needs. Any help would be appreciated.

Table A is created from a folder that consists only of movies but with different extensions.

Table B is created from a folder that consists only of pictures but with different extensions.

I have been googling Lua manuals for days now but I cannot seem to understand how to apply what I read to my needs. Any help would be appreciated.

This is a quick code I made. Instead of having 2 tables, you can have only 1, but with an internal structure. I'm using a Windows-like format. For UNIX-like format, using lower (lowercase) will help to avoid the case-sensitive.

Looking at Jorge_Luis code, I realize that merge isn't necessary at all if your final objective is to search within the table. Tables are hashes in Lua. I will try that later.
Now, I should have provided some public functions as Jorge_Luis do

Nilfred on your first post you simplified for me alot of what I was reading on google and trying to understand. The lack of code actually gave me ideas while at the same time giving me structure. I explored several different ways of attempting to achieve my goals and learned quite a bit.

Jorge_Luis although your code would run perfectly for the example movies, I would not want to rewrite the lua script each time I added a new movie to my folder, but thank you anyway. The code you supplied showed me the proper syntax and taught me to pay attention to which brackets to use.

Nilfred your second post made my head explode.
"return string.match(path, "(.-)([^\\/]-)(%.?[^%.\\/]*)$")"
What?!? Really?
I think table merging/reordering is a little over my head for now.

Update: I did manage to achieve what I wanted, although its rather sloppy. Just the fact that it works thrills me to no end. I wrote:

folder = Rainlendar_GetVariable(skin, window, "Movie_folder")
if folder ~= "" then
for filename in dirtree(folder) do
if string.find(filename:lower(), "(.*)") then
filename = string.gsub(filename, "\\", "/")
table.insert(g_Shadow4_Movie_Movies, filename)
position = string.len(folder)
filename = string.sub(filename, position + 2, -5)
table.insert(g_Shadow4_Movie_MovieName, filename)
end
end
end
This gave me Table Movies with the full path, filename and extension to use as the url for activating the movie and
Table Name with just the filename, no path or extension to use for comparison with the picture table. Next is:menu = Rainlendar_GetVariable(skin, window, "Movie_menu")
if menu ~= "" then
for filename in dirtree(menu) do
if string.find(filename:lower(), "(.*)") then
filename = string.gsub(filename, "\\", "/")
table.insert(g_Shadow4_Movie_Pic, filename)
position = string.len(menu)
filename = string.sub(filename, position + 2, -5)
table.insert(g_Shadow4_Movie_PicName, filename)
end
end
end
This gave me the pictures to use for the preview and comparison. Then is:m = 1
p = 1
repeat
repeat
if g_Shadow4_Movie_Name[m] == g_Shadow4_Movie_PicName[p] then
table.insert(g_Shadow4_Movie_Link, g_Savage_Movie_Pic[p])
m = m + 1
p = 1
break
else p = p + 1
end
until p >= #g_Shadow4_Movie_Pic
if p >= #g_Shadow4_Movie_Pic then
table.insert(g_Shadow4_Movie_Link, "None")
p = 1
m = m + 1
end
until m >= #g_Shadow4_Movie_Name
This gives me the link to the picture preview.

local function yieldtree(dir)
for entry in lfs.dir(dir) do
if entry ~= "." and entry ~= ".." then
entry=dir.."/"..entry
local attr=lfs.attributes(entry)
coroutine.yield(entry,attr)
if attr.mode == "directory" then
yieldtree(entry)
end
end
end
end

folder = Rainlendar_GetVariable(skin, window, "Movie_folder")
if folder ~= "" then
for filename in dirtree(folder) do
if string.find(filename:lower(), "(.*)") then
filename = string.gsub(filename, "\\", "/")
table.insert(g_Shadow4_Movie_Movies, filename)
position = string.len(folder)
filename = string.sub(filename, position + 2, -5)
table.insert(g_Shadow4_Movie_MovieName, filename)
end
end
end
-- This gave me Table Movies with the full path, filename and extension to use as the url for activating the movie and
-- Table Name with just the filename, no path or extension to use for comparison with the picture table. Next is:
menu = Rainlendar_GetVariable(skin, window, "Movie_menu")
if menu ~= "" then
for filename in dirtree(menu) do
if string.find(filename:lower(), "(.*)") then
filename = string.gsub(filename, "\\", "/")
table.insert(g_Shadow4_Movie_Pic, filename)
position = string.len(menu)
filename = string.sub(filename, position + 2, -5)
table.insert(g_Shadow4_Movie_PicName, filename)
end
end
end
-- This gave me the pictures to use for the preview and comparison. Then is:
m = 1
p = 1
repeat
repeat
if g_Shadow4_Movie_Name[m] == g_Shadow4_Movie_PicName[p] then
table.insert(g_Shadow4_Movie_Link, g_Savage_Movie_Pic[p])
m = m + 1
p = 1
break
else p = p + 1
end
until p >= #g_Shadow4_Movie_Pic
if p >= #g_Shadow4_Movie_Pic then
table.insert(g_Shadow4_Movie_Link, "None")
p = 1
m = m + 1
end
until m >= #g_Shadow4_Movie_Name
-- This gives me the link to the picture preview.

How function dirtree() is defined? Or where it is defined?
I put mine with unexpected result.

BTW feeding it with empty Movie_folder and Movie_menu variables result in a bug.