View Full Version : I need alittle help with list boxs
LetsRideBaby
08-06-2009, 07:15 PM
I need this code to look under one folder deep for exe files not just in the top folder but one or 2 folders under only no more then 2 folders tho..
Anyone know how i can set that up?
Code and app below..
Thanks for any help that you guys can give..
LB = "ListBox1";
--Disable listbox Updating
ListBox.SetUpdate(LB, false);
--Set default folder
folder = Dialog.FolderBrowse("Open Folder", _DesktopFolder);
--Set Default Extension
if folder ~= "CANCEL" then
ListBox.SetEnabled(LB, true);
ListBox.DeleteItem(LB, -1);
-- tbSearchFiles = {"*.doc", "*.ppt", "*.odt", "*.exe"}; set your own file types here
-- this one search all types
tbSearchFiles = {"*.exe", };
for index,type in tbSearchFiles do
file = File.Find(folder, type, true, false, nil);
if file ~= nil and file ~="CANCEL" then
--do the following for each file:
for j,file_path in file do
--add the item to the listbox, with the name visible and path as data
tbFilePath = String.SplitPath(file_path);
sFile = tbFilePath.Filename..tbFilePath.Extension;
ListBox.AddItem(LB, sFile, file_path);
end
end
end
end
--Allow the listbox to display the updated content
ListBox.SetUpdate(LB, true);
mystica
08-07-2009, 07:11 AM
Change the search sub-folders flag to true.
ie.
file = File.Find(folder, type, true, true, nil);
It won't limit the search to just on or two layers, it will search all layers ... but it will achieve the same end result.
limboo
08-07-2009, 09:33 AM
@ mystica thats not what he wants
and now it will include the foldername in the table
recurse does what you say go through all folders no matter how deep
but LetsRideBaby only wants the file find to go 2 folders deep and then stop
@ LetsRideBaby
watch out with splitpath its buggy
because if you have a folder with a .(dot) in it it will think that that is the file + extension
eg. result = splitpath("\\folder.ext\\file.exe")
it will give result.Filename = "folder"
and result.Extension = "ext"
because it searches from the left to the right and the first dot it finds will be the extension and then stops.
your better off using this little piece of code
findslash = String.ReverseFind("\\folder.ext\\file.exe", "\\", false);
result = String.Mid(k, findslash+1, -1);
now it will give result = "file.exe"
if you only want the extension use
findext = String.ReverseFind(k, ".", false);
onlyext = String.Mid("\\folder.ext\\file.exe", findext, -1);
onlyext will give ".exe"
LetsRideBaby
08-07-2009, 10:57 AM
Thanks you mystica. But i know about that but it finds them all and i dont want that..
Thanks limboo ill look in to that..
All i want the code to do is look 2 folders deep for any .exe files so i can use it for portable apps.
They usely go in folders like this..
main folder that holds every thing then in that folder you have file the .exe one that is the only i want it to find..
so it would be like..
docs/main/1.exe
docs/main/2.exe
now after the main folder inside it they maybe more .exe files hinding i dont want it to find them and list them only the ones in the 2 folder..
LetsRideBaby
08-07-2009, 11:29 AM
Here it is again but with 2 fake .exe files only the one should show not the shoundnt show.exe..
Im still kinda new to all this but i have tried in many of ways to get this to work.
limboo
08-07-2009, 04:43 PM
what are you trying to make?
there is an .apz attached for an example and offcourse the coude ;)
LetsRideBaby
08-07-2009, 09:14 PM
Sweet!! Thanks alot that is what i need.. I will give you credit for the code to..
Now if i can get the icon of the exe files to show up to that would be cool.
and hide the .exe out the end when it list the files..
I really do appreciate the help...
Its going to be a Portable Apps to launch Portable software from a usb drive..
I got to work on the images and layout for it still but i wanted to make sure it would work first..
Thanks And Thanks Again.. :yes
LetsRideBaby
08-08-2009, 11:28 AM
Here ill show you what ive been working on. Its to big to upload here so here a link to it if you all want to check it out..
http://rapidshare.com/files/265174627/LRB_Portable_Apps.apz.html
Again thanks for the help..
LetsRideBaby
08-09-2009, 07:15 AM
I got it to hind the .exe here is the code i used for that.
I see no why to add the icon tho with out some kinda plugin..
Now to find a way to fix it so i can move the window around again it stop letting me after i added a back gound image to it..
And there is no mouse down and hold for events that i know of..
Anyways thanks for the help..
-- Thanks to limboo for help with this code to look for the .exe files
LB = "ListBox1";
--Disable listbox Updating
ListBox.SetUpdate(LB, false);
--Set default folder
folder = "AutoPlay\\Docs";
--Set Default Extension
if folder ~= "CANCEL" or folder ~= "" then
ListBox.SetEnabled(LB, true);
ListBox.DeleteItem(LB, -1);
-- tbSearchFiles = {"*.doc", "*.ppt", "*.odt", "*.exe"}; set your own file types here
-- this one search all types
tbSearchFiles = {"*.exe"};
for index,type in tbSearchFiles do
file = File.Find(folder, type, true, false, nil);
if file ~= nil then
--do the following for each file:
for j, k in file do
--add the item to the listbox, with the name visible and path as data
findslash = String.ReverseFind(k, "\\", false);
filename = String.Mid(k, findslash+1, -1);
subfolder = String.Replace(k, folder, "", false);
slash = 0
--delete the first slash because it is not needed for the counting
subfolder = String.Right(subfolder, String.ToNumber(String.Length(subfolder))-1);
firstslash = String.Find(subfolder, "\\", false);
if firstslash ~= -1 then
slash = 1
afterfirstslash = String.Mid(subfolder, firstslash+1, -1);
secondslash = String.Find(afterfirstslash, "\\", false);
if secondslash ~= -1 then
slash = 2
aftersecondslash = String.Mid(afterfirstslash, secondslash+1, -1);
thirdslash = String.Find(aftersecondslash, "\\", false);
if thirdslash ~= -1 then
slash = 3
end
end
end
if slash <= 2 then
--take the file name and remove the .exe
remove_exe = String.Replace(filename, ".exe", "", false);
--Show the file name in the list box without the .exe
ListBox.AddItem(LB, remove_exe, k);
end
end
end
end
end
LetsRideBaby
08-14-2009, 12:52 PM
ok i run in to this i guess its a bug or something.
i run this code on page show
--Start show list of apps
-- Thanks to limboo for help with this code to look for the .exe files
LB = "Apps List";
--Disable listbox Updating
ListBox.SetUpdate(LB, false);
--Set default folder
folder = "AutoPlay\\Docs";
--Set Default Extension
if folder ~= "CANCEL" or folder ~= "" then
ListBox.SetEnabled(LB, true);
ListBox.DeleteItem(LB, -1);
-- tbSearchFiles = {"*.doc", "*.ppt", "*.odt", "*.exe"}; set your own file types here
-- this one search all types
tbSearchFiles = {"*.exe"};
for index,type in tbSearchFiles do
file = File.Find(folder, type, true, false, nil);
if file ~= nil then
--do the following for each file:
for j, k in file do
--add the item to the listbox, with the name visible and path as data
findslash = String.ReverseFind(k, "\\", false);
filename = String.Mid(k, findslash+1, -1);
subfolder = String.Replace(k, folder, "", false);
slash = 0
--delete the first slash because it is not needed for the counting
subfolder = String.Right(subfolder, String.ToNumber(String.Length(subfolder))-1);
firstslash = String.Find(subfolder, "\\", false);
if firstslash ~= -1 then
slash = 1
afterfirstslash = String.Mid(subfolder, firstslash+1, -1);
secondslash = String.Find(afterfirstslash, "\\", false);
if secondslash ~= -1 then
slash = 2
aftersecondslash = String.Mid(afterfirstslash, secondslash+1, -1);
thirdslash = String.Find(aftersecondslash, "\\", false);
if thirdslash ~= -1 then
slash = 3
end
end
end
if slash <= 2 then
--take the file name and remove the .exe
remove_exe = String.Replace(filename, ".exe", "", false);
--Show the file name in the list box without the .exe
ListBox.AddItem(LB, remove_exe, k);
end
end
end
end
end
--Allow the listbox to display the updated content
ListBox.SetUpdate(LB, true);
-- show how many apps they have installed
HowManyExes = ListBox.GetCount(LB);
Label.SetText("How Many Apps Installed", "Apps # "..HowManyExes);
then i have this code on a button
-- Determine if an error occurred.
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
else
--Get the file to install _TempFolder..
FileToInstall = Dialog.FileBrowse(true, "Locate LRB Apps Install File", _DesktopFolder, "LRB Apps Install File (*.lrb*)|*.lrb*|", "", "lrb", false, false);
-- Show the status dialog.
StatusDlg.Show();
StatusDlg.ShowProgressMeter(true);
--replace the .lrb with .zip
Renamed = String.Replace(FileToInstall[1], ".lrb", ".zip", false);
--Rename the file to .zip
File.Rename(FileToInstall[1], Renamed);
-- Extract the chosen files to the zip archive.
Zip.Extract(Renamed, {"*.*"}, "AutoPlay\\Docs\\Portable Software", true, true, "", ZIP_OVERWRITE_ALWAYS, nil);
--Rename the file back.
File.Rename(Renamed, FileToInstall[1]);
-- Hide dialog
StatusDlg.Hide();
end
now when i install an app it copy it and installs it fine but i have a button with the code on the top so i can refresh the list but remove all stuff from the list when i hit the button and it only does this if i run the 2ed code..
i can add them by copy and pasting them and hit the refresh button and there show right..
i think this might be a bug in the Dialog.FileBrowse
Any help here?
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.