Fractured Posted June 6, 2017 Posted June 6, 2017 Hi! New to AutoIt. I am working on a script/stand alone compiled program for windows that uses a GUI and allows a user to input drawing number, search for said file, display the files found, and select the proper file type to open. Having sifted through the forum I have found a lot of useful information for this. I only have a few questions. Do I need to use a recursive search if I can get the directory needed by the first 3 numbers of the drawing name? All of our drawings are named ex. 193-8883, so the folder would be DWG193. I know I can use a String function to just read the first 3 numbers in the string. then go to just that folder. Im assuming no.... Do I need to use _FileListToArray if there is more than one drawing? We have drawings in PDF,DWG,etc. The goal is for the search to display the found files in a list window of the GUI, then be able to select the one to open using ShellExecute. I have the GUI made using Koda, and am slowly adding the code snippets I have found to make it work. When I can figure out how to post script I can show what I have so far! Still very "green"! Thanks in advance
Moderators JLogan3o13 Posted June 6, 2017 Moderators Posted June 6, 2017 Hi, @Fractured welcome to the forum. If you can get the directory from the beginning of the filename, and you know the drawing won't be in a sub of that directory, you don't have to use a recursive search: $userChosenFile = "192-8883.pdf" If FileExists("DWG193\" & $userChosenFile) Then ;fileopen, or other process EndIf If the drawing could be in directory DWG193, or DWG193\PDFs, DWG193\Docs, etc., then yes, a recursive search is necessary. Regarding having more than one drawing, _FileListToArray is certainly one way to go about it. How are you planning the logic that decides which file (PDF, DWG, etc) is chosen, are you going to prompt the user? Or are you looking to simply find the 192-8883 file, regardless of its extension, and open it in the correct application? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Fractured Posted June 6, 2017 Author Posted June 6, 2017 Thanks for the quick response! Thank goodness on no need of recursive!! That looks a little to much for my skill level!! As for the more than one drawing issue....I was going to have the search return all files with the search string --"192-8883"-- regardless of extension(.pdf, .dwg...) and create a list box of the returned files with the extensions to choose from. If that makes sense.... So code would go something like this **All drawing files are listed in this format ###-####.ext***** *****All Folders are formated DWG###******* user inputs $sDWG (ex.193-8883), search function trims $sDWG to "193" reassigns to $newstring and will goto directory DWG+$newstring, searches for all files with name $sDWG.*, places those files into a listbox, user selects file from list box to be opened using Shellexec command. Hope that makes sense!
Fractured Posted June 6, 2017 Author Posted June 6, 2017 This is an example of what im working with as code... _Fsearch() Func _FSearch() $SourceFolder = "S:\Drawing Vault\DWG VAULT\DWG"&$DWGSL&"\" ;Attempt at naming my Source Folder ;Msgbox($MB_SYSTEMMODAL, "Test1",$SourceFolder) ; List all the files and folders in the desktop directory using the default parameters. Local $aFileList = _FileListToArray($SourceFolder,$DWG&".*") If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") Exit EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") Exit EndIf ; Display the results returned by _FileListToArray. _ArrayDisplay($aFileList, "$aFileList") EndFunc ;==>Example I cant seem to figure out the _FileListToArray..trying to have it search for files with $DWG in the name, not caring for the ext...can I use wildcards ? or *? Thought I saw I could but going blind reading!! Thanks!
Subz Posted June 6, 2017 Posted June 6, 2017 Maybe something like this: #include <Array.au3> #include <File.au3> _Fsearch("192-8883") Func _FSearch($sSearch) Local $sSearchMask = StringLeft($sSearch, 3) & "*.*" Local $sSearchPath = "S:\Drawing Vault\DWG VAULT\DWG" & StringLeft($sSearch, 3) MsgBox(4096, "Search Info", "Search Mask: " & $sSearchMask & @CRLF & "Search Path: " & $sSearchPath) Local $aFileList = _FileListToArrayRec($sSearchPath, $sSearchMask, 1, 1, 0, 2) If @error = 1 Then MsgBox(4096, "", "Path was invalid.") Exit ElseIf @error = 4 Then MsgBox(4096, "", "No file(s) were found.") Exit EndIf _ArrayDisplay($aFileList, "$aFileList") EndFunc
Fractured Posted June 7, 2017 Author Posted June 7, 2017 Thanks Subz! I will give this a look see...I forgot that the drawing files also tend to have a revision level attached to the end of the name... i.e. 193-8887A.pdf ---So I will need to match string I think as opposed to looking for a literal name. Thats why I was trying to figure out if wild cards were usable. i.e. 193-8887?.* to find all instances that have 193-8887 in them regardless of ext.
Subz Posted June 7, 2017 Posted June 7, 2017 The function above should search for 192*.* as we trim the parameter down, however if you want to use the parameter + *.* then just change Local $sSearchMask to: $sSearch & "*.*" then it should search for 192-8883*.* Hope that makes sense.
Fractured Posted June 7, 2017 Author Posted June 7, 2017 expandcollapse popup;***************************************** ;DWG_File_Search.au3 by Charles Wright ;Created with ISN AutoIt Studio v. 1.05 ; ;Help from JLogan3o13, Subz ;***************************************** ;######################################## ;Include ;######################################## #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> ;######################################## ;Some Variables held for later ;######################################## ;######################################### ;Koda GUI ;######################################### #Region ### START Koda GUI section ### Form= $Search = GUICreate("DWG Vault Search", 335, 170, 192, 124) $DWG = GUICtrlCreateInput("DWG", 24, 32, 121, 21) $Button1 = GUICtrlCreateButton("Search", 48, 56, 75, 25) $Returned = GUICtrlCreateList("", 168, 32, 121, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; Add columns ;_GUICtrlListView_AddColumn($idListview, "Drawings", 100) ;########################################## ;Search Field / Button Interaction ;########################################## While 1 $msg = GUIGetMsg() Select Case $msg = $Button1 Local $DWGtemp = GUICtrlRead($DWG) ;Place Holder for $DWG Local $DWGSL = StringLeft($DWGtemp,3) ;Store just first 3 characters of $DWG Call ("_FSearch") EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop sleep(100) WEnd ;############################################ ;File Search Function ;############################################ _Fsearch() Func _FSearch() Local $SourceFolder = "S:\Drawing Vault\DWG VAULT\DWG" & $DWGSL &"\" ;Verified working ;Msgbox($MB_SYSTEMMODAL, "Test1",$SourceFolder) Local $sSearchMask = $DWGtemp & "*.*" ;Verified working ;Msgbox($MB_SYSTEMMODAL, "Test1",$DWGtemp) ;Msgbox($MB_SYSTEMMODAL, "Test1",$sSearchMask) Local $aFileList = _FileListToArrayRec($SourceFolder, $sSearchMask, 1, 1, 0, 2) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") Exit EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") Exit EndIf ;Display the results returned by _FileListToArray. _ArrayDisplay($aFileList, "$aFileList") EndFunc ;############################################ ;Window Close ;############################################ While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Ok..this is what I have so far. Using Message Boxes I have verified that it now goes to the proper directory, uses the proper search form, and displays the array...So from here I may have to switch to GUI help side of forum. If you run the script you will see I have a list box in the GUI I would like the array placed, so the user can then select the drawing and have it open using the Shell Execute command....just cant seem to figure out how to get the array in the box..... Maybe use _GUICtrlListView_AddArray, but if so should my GUI List box have been made with GUICtrlCreateListView instead? hmmmmm...
Subz Posted June 7, 2017 Posted June 7, 2017 Just use: $sFileList = _ArrayToString($aFileList, "|", 1) GUICtrlSetData($Returned, $sFileList)
Fractured Posted June 7, 2017 Author Posted June 7, 2017 Will do! Pain doing real job and side job at same time!
Fractured Posted June 7, 2017 Author Posted June 7, 2017 Yeah! That's worked great to populate the List box!! But now the serious question.....how can a user select which one to open? I looked up the _ArrayToString function and it says it turns the array into a single string, split with the "|" between the array elements. Newbie Question....if its all one string, just delimited, seems you couldnt unless I just cant figure it out....which being a greenie, I can easily believe!
Subz Posted June 7, 2017 Posted June 7, 2017 Normally you would add another button and what ever the user selects you can then perform an action for example: expandcollapse popup;***************************************** ;DWG_File_Search.au3 by Charles Wright ;Created with ISN AutoIt Studio v. 1.05 ; ;Help from JLogan3o13, Subz ;***************************************** ;######################################## ;Include ;######################################## #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> ;######################################## ;Some Variables held for later ;######################################## Global $g_sFilePath = "S:\Drawing Vault\DWG VAULT\" ;######################################### ;GUI ;######################################### GUICreate("DWG Vault Search", 335, 165) $idSearch = GUICtrlCreateInput("DWG", 10, 10, 190, 20) $idSearchButton = GUICtrlCreateButton("Search", 205, 10, 120, 20) $idFileList = GUICtrlCreateList("", 10, 35, 315, 105) $idSelectButton = GUICtrlCreateButton("Select", 205, 138, 120, 20) GUISetState() ;########################################## ;Search Field / Button Interaction ;########################################## While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idSearchButton GUICtrlSetData($idFileList, GUICtrlRead($idSearch) = "" ? "" : _FSearch(GUICtrlRead($idSearch))) Case $idSelectButton Local $sResult = GUICtrlRead($idFileList) MsgBox(4096, "Selected File", $sResult) EndSwitch WEnd ;############################################ ;File Search Function ;############################################ Func _FSearch($sSearch = "DWG") Local $idSearchSL = StringLeft($sSearch, 3) ;~ Store just first 3 characters of $idSearch Local $sSourceFolder = $g_sFilePath & "\DWG" & $idSearchSL If FileExists($sSourceFolder) = 0 Then MsgBox(4096, "File Path Error", "Folder : " & $sSourceFolder & " does not exist.") Return "" EndIf Local $sSearchMask = $sSearch & "*.*" Local $aFileList = _FileListToArrayRec($sSourceFolder, $sSearchMask, 1, 1, 0, 2) Switch @error Case 1 MsgBox(4096, "File List To Array Error", "Path not found or invalid") Return "" Case 2 MsgBox(4096, "File List To Array Error", "Invalid Include parameter") Return "" Case 3 MsgBox(4096, "File List To Array Error", "Invalid Exclude parameter") Return "" Case 4 MsgBox(4096, "File List To Array Error", "Invalid Exclude_Folders parameter") Return "" Case 5 MsgBox(4096, "File List To Array Error", "Invalid $iReturn parameter") Return "" Case 6 MsgBox(4096, "File List To Array Error", "Invalid $iRecur parameter") Return "" Case 7 MsgBox(4096, "File List To Array Error", "Invalid $iSort parameter") Return "" Case 8 MsgBox(4096, "File List To Array Error", "Invalid $iReturnPath parameter") Return "" Case 9 MsgBox(4096, "File List To Array Error", "No files/folders found") Return "" EndSwitch Return _ArrayToString($aFileList, "|", 1) EndFunc
Fractured Posted June 7, 2017 Author Posted June 7, 2017 Thats awesome!! ok..so ive got a lot of reading todo!!! Thanks!! Feel I was on right track for some of it but lack of knowledge was killing me. But, I am going to go over this thing and comment the heck out of it and research it to death!! Thanks again for the help and knowledge.
Fractured Posted June 7, 2017 Author Posted June 7, 2017 Works like a champ! Last question.....I looked up the _FileListToArrayRec and saw that you can add exclusions. I tried to exclude *.prt files as the engineers have started dumping them in the vault. (Found this out testing the script) Problem is it is killing the script.... Local $aFileList = _FileListToArrayRec($sSourceFolder, $sSearchMask; "*|*.prt", 1, 1, 0, 2) ==> Error parsing function call.: Local $aFileList = _FileListToArrayRec($sSourceFolder, $sSearchMask Local $aFileList = _FileListToArrayRec($sSourceFolder, ^ ERROR Does it have to do with the string being the filter or did I not add the next filter correctly? Or would I have to add it to the $sSearchMask part of the script? Sorry to be a pain in the rear....
Developers Jos Posted June 7, 2017 Developers Posted June 7, 2017 It simply is a wrong syntax with that SemiColon in there. Check the helpfile for the proper syntax. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Fractured Posted June 7, 2017 Author Posted June 7, 2017 Got it right after I posted!! You were just to fast for me to correct myself!! Ty Jos!
Fractured Posted June 8, 2017 Author Posted June 8, 2017 Ok, so the script works great.....too great!! Here is my new hurdle...I did not account for files being included with the search that have the search term in them.. i.e. I search for 193-1008 --- I get 193-1008, 193-10088, 193-10081, etc... Is there a way to filter out all but the 193-1008 files? Thanks to Subz and Jos I have it sorting the right extensions....now its just the naming thats killing me.. I tried doing a second searchmask, but it wigs out...tried _ArraySort and _ArrayDelete but i have now learned my array knowledge is poo.... **The _ArrayDisplay($aFileList, "1D display") in the code was so I could see how the array was formatted** Any pointers/directions/abuse very welcome!! expandcollapse popup;***************************************** ;DWG_File_Search.au3 by Charles Wright ;Created with ISN AutoIt Studio v. 1.05 ; ;Help from JLogan3o13, Subz, Jos ;***************************************** ;######################################## ;Include ;######################################## #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> ;######################################## ;Some Variables held for later ;######################################## Global $g_sFilePath = "S:\Drawing Vault\DWG VAULT\" ;######################################### ;GUI ;######################################### GUICreate("DWG Vault Search", 335, 165) $idSearch = GUICtrlCreateInput("", 10, 10, 190, 20) $idSearchButton = GUICtrlCreateButton("Search", 205, 10, 120, 20) $idFileList = GUICtrlCreateList("", 10, 35, 315, 105) $idSelectButton = GUICtrlCreateButton("Select", 205, 138, 120, 20) GUISetState() ;########################################## ;Search Field / Button Interaction ;########################################## While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idSearchButton GUICtrlSetData($idFileList, GUICtrlRead($idSearch) = "" ? "" : _FSearch(GUICtrlRead($idSearch))) Case $idSelectButton Local $sResult = GUICtrlRead($idFileList) ShellExecute($sResult) EndSwitch WEnd ;############################################ ;File Search Function ;############################################ Func _FSearch($sSearch = "DWG") GUICtrlSetData($idFileList,"") Local $idSearchSL = StringLeft($sSearch, 3) ;~ Store just first 3 characters of $idSearch Local $sSourceFolder = $g_sFilePath & "\DWG" & $idSearchSL If FileExists($sSourceFolder) = 0 Then MsgBox(4096, "File Path Error", "Folder : " & $sSourceFolder & " does not exist.") Return "" EndIf Local $sSearchMask = $sSearch & "*.*" Local $aFileList = _FileListToArrayRec($sSourceFolder, $sSearchMask & "*|*.cdr", 1, 0, 1, 2) ; _FileListToArrayRec(Path,Mask,Files Only,No Recurs,No Sort,File Name Only) _ArrayDisplay($aFileList, "1D display") Switch @error Case 1 MsgBox(4096, "File List To Array Error", "Path not found or invalid") Return "" Case 2 MsgBox(4096, "File List To Array Error", "Invalid Include parameter") Return "" Case 3 MsgBox(4096, "File List To Array Error", "Invalid Exclude parameter") Return "" Case 4 MsgBox(4096, "File List To Array Error", "Invalid Exclude_Folders parameter") Return "" Case 5 MsgBox(4096, "File List To Array Error", "Invalid $iReturn parameter") Return "" Case 6 MsgBox(4096, "File List To Array Error", "Invalid $iRecur parameter") Return "" Case 7 MsgBox(4096, "File List To Array Error", "Invalid $iSort parameter") Return "" Case 8 MsgBox(4096, "File List To Array Error", "Invalid $iReturnPath parameter") Return "" Case 9 MsgBox(4096, "File List To Array Error", "No files/folders found") Return "" EndSwitch Return _ArrayToString($aFileList, "|", 1) EndFunc
Moderators JLogan3o13 Posted June 8, 2017 Moderators Posted June 8, 2017 (edited) If is it only 193-1008.<pdf,doc,etc>, can you search on 193-1008.? Otherwise you'll probably have to resort to a regex to ensure you cover all the bases. Edited June 8, 2017 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Fractured Posted June 8, 2017 Author Posted June 8, 2017 ill give it a try a and see what works Thanks! Will read up on regex just in case!
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