View Full Version : read from folder and write it to menubar
GoOgLe
03-18-2008, 02:27 PM
is it possible to show all exe files in the folder on menubar ?
jassing
03-20-2008, 11:14 AM
is it possible to show all exe files in the folder on menubar ?
at design time or runtime?
I don't have ams -- but reading the docs; it looks like something like this might work:
local cFolder = Dialog.FolderBrowse("Which folder to fill from?",_SourceFolder);
if Folder.DoesExist( cFolder ) then
local tFiles = File.Find(cFolder,"*.exe");
if Table.Count( tFiles ) > 0 then
local x = 0;
local tMenu= Application.GetMenu();
tMenu.ID=200;
tMenu.Text="Available EXE's";
tMenu.Enabled = true;
tMenu.Checked = false;
tMenu.SubMenu={};
for x=1,Table.Count(tFiles) do
tMenu.SubMenu[x]={};
tMenu.SubMenu[x].Text= tFiles[x];
tMenu.SubMenu[x].ID = 200+x;
tMenu.SubMenu[x].Checked = false;
tMenu.SubMenu[x].Enabled=true;
end
Application.SetLastError(0);
Application.SetMenu( tMenu );
local nErr = Application.GetLastError();
if nErr > 0 then
Dialog.Message("Error",_tblErrorMessages[ nErr ] );
end
else
Dialog.Message("Oops","No files found");
end
end
100% untested, I don't have ams -- and suf7 doesn't have a menubar.
GoOgLe
03-20-2008, 11:52 AM
thanks for reply jassing
on preload but i got error
http://img399.imageshack.us/img399/5207/erroruv8.jpg
jassing
03-20-2008, 11:58 AM
Looks like this line is erroring out:
local tMenu= Application.GetMenu();
Try changing it to
local tMenu={};
or better; find out why GetMenu is failing...
GoOgLe
03-20-2008, 12:02 PM
when i choose desktop i get error but when i choose my documents no error but no item on menu bar...
jassing
03-20-2008, 12:47 PM
when i choose desktop i get error but when i choose my documents no error but no item on menu bar...
What error do you get? I would think that no exe's would be in the desktop or my documents...
Like I said; 100% untested; I just did that from reading the documents. I'll request a demo download and try it -- I probably won't get the download until today; but I'm leaving for the weekend early tomorrow... so might not be until monday or tuesday.
GoOgLe
03-20-2008, 01:06 PM
thanks alot jassin
i think eroor i get on desktop is because i have no exe file but in my documents i have exe file but i cant write to menubar
jassing
03-20-2008, 03:40 PM
thanks alot jassin
i think eroor i get on desktop is because i have no exe file but in my documents i have exe file but i cant write to menubar
What error are you getting?
The fact that it doesn't work doesn't suprise me since I've never worked with menu bars; but errors? I can't find anything that would generate an error...
My repairs just took a turn for the worst, and I have to head off island to pick up some materials. This will push back when I can get to this -- I will put in for a eval donwload request before I leave.
-josh
GoOgLe
03-20-2008, 04:36 PM
this didnt work... !!!
local cFolder = Dialog.FolderBrowse("Which folder to fill from?",_SourceFolder);
if Folder.DoesExist( cFolder ) then
local tFiles = File.Find(cFolder,"*.exe");
if Table.Count( tFiles ) > 0 then
local x = 0;
local tMenu={};
tMenu.ID=200;
tMenu.Text="Available EXE's";
tMenu.Enabled = true;
tMenu.Checked = false;
tMenu.SubMenu={};
for x=1,Table.Count(tFiles) do
tMenu.SubMenu[x]={};
tMenu.SubMenu[x].Text= tFiles[x];
tMenu.SubMenu[x].ID = 200+x;
tMenu.SubMenu[x].Checked = false;
tMenu.SubMenu[x].Enabled=true;
end
Application.SetLastError(0);
Application.SetMenu( tMenu );
local nErr = Application.GetLastError();
if nErr > 0 then
Dialog.Message("Error",_tblErrorMessages[ nErr ] );
end
else
Dialog.Message("Oops","No files found");
end
end
jassing
03-20-2008, 04:42 PM
Yes you've said that; which line is giving you an ERROR and what is the error?
GoOgLe
03-20-2008, 04:48 PM
i dont get error but i dont files listed either !!!
jassing
03-20-2008, 04:58 PM
i dont get error but i dont files listed either !!!
OK - you had said it errored for you; that supprised me; but not getting files; that doesn't -- as I don't fully know how to work with Menu's yet. I'll check it out. be patient; might not be until next week.
-josh
jassing
03-21-2008, 11:40 PM
You're lucky, I had to pay for it; but there was wifi at the place I'm at...
This works for me... hope it does for you.
tblMenu = Application.GetMenu();
local nNewitem = Table.Count(tblMenu)+1;
tblMenu[nNewitem] ={};
tblMenu[nNewitem].Text = "&Available Files";
tblMenu[nNewitem].ID = 1000;
tblMenu[nNewitem].Checked = false;
tblMenu[nNewitem].Enabled = true;
tblMenu[nNewitem].SubMenu = {};
local tFiles = File.Find( _SystemFolder, "*.exe");
local x = 0;
for x = 1,Table.Count(tFiles) do
tblMenu[nNewitem].SubMenu[x] = {};
tblMenu[nNewitem].SubMenu[x].Text = tFiles[x];
tblMenu[nNewitem].SubMenu[x].ID = 1000+x;
tblMenu[nNewitem].SubMenu[x].Checked = false;
tblMenu[nNewitem].SubMenu[x].Enabled = true;
end
Application.SetMenu(tblMenu);
jackdaniels
03-22-2008, 01:58 AM
jassing thanks alot alot for answering
but i have one more problem with it... if i the folder doesnt include any exe file i get that error !!!
http://img404.imageshack.us/img404/7931/errorof1.jpg
GoOgLe
03-22-2008, 08:59 AM
thanks jassing
@jackdaniels
i would say the same thing;
perfect code but if no exe in folder u get error
holtgrewe
03-22-2008, 09:34 AM
To test for empty table try:
if (tFiles) then
-- your code
else
Dialog.Message("No Files!", "") -- or whatever
end
after the File.Find...
hth
GoOgLe
03-22-2008, 10:35 AM
thanks jassing & holtgrewe
another question is it possible to hide path of the file ??? just show the name of it...
http://img176.imageshack.us/img176/1654/errornt5.jpg
example: App.exe
jassing
03-22-2008, 11:09 AM
thanks jassing & holtgrewe
another question is it possible to hide path of the file ??? just show the name of it...
http://img176.imageshack.us/img176/1654/errornt5.jpg
example: App.exe
Absolutely -- have a look at the File.SplitPath() and write a function around it that returns just the file name & extension.
GoOgLe
03-22-2008, 11:15 AM
when i click the menubar it doesnt run the file ???
holtgrewe
03-22-2008, 11:16 AM
Yeh, it requires string manipulation.
this is not tested, but this will give you the general idea.
sLength=String.Length(""..yourstring) -- find the length of your string
sStartPos=String.ReverseFind(""..yourstring, "\\", true) -- reverse find the "\"
shortName = String.Mid(""..yourstring, sStartPos +1, sLength)
Play around with this, you should be able to get it to work for you.
hth
jassing
03-22-2008, 11:23 AM
when i click the menubar it doesnt run the file ???
Google -- you said nothing about what you wanted to do with the menu once you filled it... I gotta say; I feel like we're doing your work for you....
Just because you put some words in a menu; it doesn't mean that AMS will know what to do with it. YOu'll need to add code to the page's "Script/ On Menu" section.
This will enable you to do SOMETHING with it when your user selects a menu item. You will need to evaluate the menu's text (from the menu item ID) and then use File.Run()
-josh
jackdaniels
03-22-2008, 11:30 AM
Not Tested But It Must Be Something Like That
if e_ID > 1000 then
runID=e_ID-1000
result = File.Run(runID, "", "", SW_SHOWNORMAL, false);
end
jassing
03-22-2008, 11:39 AM
Not Tested But It Must Be Something Like That
if e_ID > 1000 then
runID=e_ID-1000
result = File.Run(runID, "", "", SW_SHOWNORMAL, false);
end
Since I'm new to AMS (actually; just found the menu question interesting) I'm not even following that code.. but I just tried this in the On Menu action:
if e_ID > 1000 then
File.Run(e_ItemInfo.Text );
end
GoOgLe
03-22-2008, 11:44 AM
u r new to ams but u know coding much more than me jassing... i am new to coding and i am trying really hard to find solutions...
still learning:rolleyes
jassing
03-22-2008, 04:41 PM
u r new to ams but u know coding much more than me jassing... i am new to coding and i am trying really hard to find solutions...
still learning:rolleyes
You'll never learn it if you have everyone else do it... But you've now got the code to load up a menu with file names, and then run it when selected...
Good luck; I'll keep an eye out on the ams forums from time to time to see if something else interesting pops up.
-j
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.