thepip3r Posted January 17, 2008 Share Posted January 17, 2008 I'm using FindFileFirstFile and FindFileNextFile in a function I wrote to take a given directory and do a recursive search on every file and folder underneath of the passed path and builds a hierarchical menu based off of that. The function works exactly how I want it to except the button on click errors out and I'm not sure if it's because of an incorrect usage of the GUICtrlSetOnEvent or because of an error with my functions. Could anyone please take a look and offer suggestions?? I'd greatly appreciate it. Function to build a hierarchical menu based off of a given path: __DirtoMenu("C:\Documents and Settings\All Users\Start Menu\Programs",$menuAllProgsParent); $menuAllProgsParent is the var for the parent menu I want the tree to start from. Func __DirtoMenu($fp,$menu) Dim $arrFile,$newMenu,$val,$fp,$file,$search,$menu,$fileAttrib,$menuTempParent $search = FileFindFirstFile($fp & "\*.*") If $search = -1 Then GUICtrlCreateMenuItem("<Parsing Error>",$menuTempParent) While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $fileAttrib = FileGetAttrib($fp & "\" & $file) If @error Then GUICtrlCreateMenuItem("<Parsing Error>",$menuTempParent) ExitLoop Else If StringInStr($fileAttrib, "D") Then $newMenu = GUICtrlCreateMenu($file,$menu) __DirtoMenu($fp & "\" & $file,$newMenu) Else If $file <> "desktop.ini" Then If StringRight($file,4) = ".lnk" Or StringRight($file,4) = ".url" Then GUICtrlCreateMenuItem(StringTrimRight($file,4),$menu) GUICtrlSetOnEvent(-1,"__ExePath"); <---- Problem Section !!!!!!!!!!!!!!!! Else GUICtrlCreateMenuItem($file,$menu) GUICtrlSetOnEvent(-1,"__ExePath"); <---- Problem Section !!!!!!!!!!!!!!!! EndIf EndIf EndIf EndIf WEnd FileClose($search) EndFunc Here are the custom functions I wrote to try and get the menu on-clicks to try and execute the path: Func __ExePath() ShellExecute(GUICtrlRead(@GUI_CtrlId,1)) EndFunc Func __FileOpen($path="") If $path <> "" Then ShellExecute($path) EndIf EndFunc When I click on the buttons generated by the function as it is written above, I get an error citing the ShellExecute(GUICtrlRead(@GUI_CtrlId,1)) stating: Error: Unable to execute the external program. The system cannot find the file specified. And when I replace __ExePath with __FileOpen($file) in my __DirtoMenu() function, my script errors on execution citing an unknown function on line 225 -- the line showing the first ; <---- Problem Section !!!!!!!!!!!!!!!! Any help would be greatly greatly appreciated... TIA. My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume Link to comment Share on other sites More sharing options...
WolfWorld Posted January 17, 2008 Share Posted January 17, 2008 Whole script so i can see the error Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
Siao Posted January 17, 2008 Share Posted January 17, 2008 (edited) The text of your menu items doesn't have file extension let alone full path, so what exactly do you expect ShellExecute to do with it, unless by some lucky chance a file like that does exist somewhere on system path and can be executed (which wouldn't be what you intended anyway)? Edited January 17, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
thepip3r Posted January 17, 2008 Author Share Posted January 17, 2008 (edited) Siao -- you're spot on. I actually came upon that conclusion almost immediately after my post and I'm sorry for not making an update before you posted. I figured it out by changing my function to this: Func __ExePath() MsgBox(0,"",GUICtrlRead(@GUI_CtrlId,1)) ShellExecute(GUICtrlRead(@GUI_CtrlId,1)) EndFunc ...So then I guess my question changes to how do I make the button to say the executable's/link's/URL's name but when clicked, passes the path? Is there a way to store multiple values in a button?? Because in my function, I do have the path to the file, I just can't pass it the same way or my whole button would be named the absolute path to the file... My ultimate intention is to (as in the example) build the menu of the All Users/Start Menu/Programs directory, create submenus when the function encounters another directory, and when finally when it gets to a file inside of the directory, it writes the name of the file to the menu but executes the path to the file in whatever program or way the systems it's being run from knows how to run that particular file... any further help? Edited January 17, 2008 by thepip3r My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now