soblome83 Posted July 9, 2013 Share Posted July 9, 2013 I am new to the world of AutoIT and trying to get up to speed. I am currently stuck on this exercise. Recursive File Search: Allow the user to specify a folder location to search for all files or folders that contain a set of characters that they specify. Develop an easy-to-use way for the user to specify more than once search criteria, and also more than one search folder, and an effective method for outputting the results. I have written the following which will return the contents of the initial folder and contents of the folders inside that folder but I am not sure how to proceed. At some point in no longer returned the folder names in the array it creates, not sure where I went wrong. Any help would be appreciated. expandcollapse popup#NoTrayIcon #include <Array.au3> Global $aSearch1[1], $i, $found $SearchFold = InputBox("", "Input the folder you want to search","C:\blablabla") $SearchString = InputBox("", "Input value you want to search for", "*.*") ;~ $SearchString = "*" & $SearchString & "*" _FileSearch( $SearchFold, $SearchString ) _ArrayDisplay( $aSearch1, "Search Results" ) $i = 0 Func _FileSearch( $startfold, $searchval ) ; declares function FileChangeDir($startfold) ; changes the working directory, directory is being searched $search = FileFindFirstFile( $searchval ) If $search = -1 Then ; Check if the search was successful MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile( $search ) If @error Then ExitLoop $found = $startfold & "\" & $file $dirchk = StringInStr(FileGetAttrib($found), "D" ) ;directory check Select Case $dirchk > 0 _FileSearch( $found, $searchval ) ;recurse if directory found Case $dirchk = 0 $found = $startfold & "\" & $file ;return $found if not a directory EndSelect $aSearch1[$i] = $found ;write found to the array $i = $i + 1 ;increase the value of $i ReDim $aSearch1[$i +1] ;redim the array WEnd ReDim $aSearch1[UBound( $aSearch1 ) -1] ;trim the array $i = UBound($aSearch1) -1 FileClose($search) ; Close the search handle EndFunc Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 9, 2013 Moderators Share Posted July 9, 2013 I would personally check out Melba's RecFileListToArray, read all the files and folders into the array, and then present only those that match your query value. http://www.autoitscript.com/forum/index.php?showtopic=126198 "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! Link to comment Share on other sites More sharing options...
spudw2k Posted July 9, 2013 Share Posted July 9, 2013 I'm a big fan of _FilelistToArray. Here's is how I have used it recursively. #include <File.au3> $outputfile = "output.txt" $rootdir = @ScriptDir FileOpen($outputfile,2) _SearchFolder($rootdir) FileClose($outputfile) Func _SearchFolder($folder,$filter="*") $files = _FileListToArray($folder,$filter,1) $folders = _FileListToArray($folder,$filter,2) _FileFunc($files,$folder) _FolderFunc($folders,$folder) EndFunc Func _FileFunc($files,$folder) For $i = 1 To UBound($files)-1 FileWrite($outputfile, $folder & "\" & $files[$i] & @CRLF) Next EndFunc Func _FolderFunc($folders,$parentdir) For $i = 1 To UBound($folders)-1 _SearchFolder($parentdir & "\" & $folders[$i]) Next EndFunc Melba's UDF is also very good and well written. Just wanted to give you another example. I agree that exercises can be fun and useful, but sometimes reinventing the wheel isn't worth the time and effort. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
DXRW4E Posted July 9, 2013 Share Posted July 9, 2013 >_FileListToArrayEx Ciao. Link to comment Share on other sites More sharing options...
soblome83 Posted July 11, 2013 Author Share Posted July 11, 2013 Thanks for the help/input everyone, although I understand reinventing the wheel isn't usually worth it, in this case it has helped me to gain a better understanding of autoit, which was what was intended when I was assigned this training exercise. Link to comment Share on other sites More sharing options...
spudw2k Posted July 12, 2013 Share Posted July 12, 2013 ...in this case it has helped me to gain a better understanding of autoit, which was what was intended when I was assigned this training exercise. Well done Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
guinness Posted July 12, 2013 Share Posted July 12, 2013 Learning is great! It's when people say things such as "I don't like using other peoples UDFs, so I want to create my own" is when you're re-inventing the wheel. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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