Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Recursive file/folder search - training exercise

$
0
0

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.
AutoIt         
#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
 
 

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>