Jump to content

A better file search utility


keyfinger
 Share

Recommended Posts

I don't know if anyone else has a better utility or what, but I did some research and created this utility which seems to work pretty well without a lot of code. Let me know what you think.

#include <Array.au3>

$array = FileSearch("C:\")
_ArrayDisplay($array, "Search Results")

Exit

Func FileSearch($StartRoot)
   Local $Filter[2]
   Local $Search, $File, $Files
   
   $Filter[0] = ".au3"
   $Filter[1] = ".old"
   
   SplashTextOn("Searching...", "", 800, 50, -1, -1, 4, "Arial", 10)
   
   $Search = FileFindFirstFile($StartRoot & "*.*")
   If $Search = -1 Then Exit(@error)
   
   While 1
      $File = FileFindNextFile($Search)
      If @error Then ExitLoop
      
      If StringInStr(FileGetAttrib($StartRoot & $File), "D") Then
         ControlSetText("Searching...", "", "Static1", $StartRoot & $File)
         FileSearchSub($StartRoot & $File & "\", $Filter, $Files)
      ElseIf StringInStr($File, $Filter[0]) Or StringInStr($File, $Filter[1]) Then
         $Files = $Files & ";" & $StartRoot & $File
      EndIf
   WEnd
   FileClose($Search)
   
   SplashOff()
   
   $Files = StringTrimLeft($Files, 1)
   Return StringSplit($Files, ";")
EndFunc ; FileSearch

Func FileSearchSub($SearchSub, ByRef $Filter, ByRef $Files)
   Local $Search, $File
   
   $Search = FileFindFirstFile($SearchSub & "*.*")
   If $Search = -1 Then Return
   
   While 1
      $File = FileFindNextFile($Search)
      If @error Then ExitLoop
      
      If StringInStr(FileGetAttrib($SearchSub & $File), "D") Then
         ControlSetText("Searching...", "", "Static1", $SearchSub & $File)
         FileSearchSub($SearchSub & $File & "\", $Filter, $Files)
      ElseIf StringInStr($File, $Filter[0]) Or StringInStr($File, $Filter[1]) Then
         $Files = $Files & ";" & $SearchSub & $File
      EndIf
   WEnd
   FileClose($Search)
EndFunc ; FileSearchSub

Link to comment
Share on other sites

I don't know if anyone else has a better utility or what, but I did some research and created this utility which seems to work pretty well without a lot of code. Let me know what you think.
#include <Array.au3>

$array = FileSearch("C:")
_ArrayDisplay($array, "Search Results")

Exit

Func FileSearch($StartRoot)
   Local $Filter[2]
   Local $Search, $File, $Files
   
   $Filter[0] = ".au3"
   $Filter[1] = ".old"
   
   SplashTextOn("Searching...", "", 800, 50, -1, -1, 4, "Arial", 10)
   
   $Search = FileFindFirstFile($StartRoot & "*.*")
   If $Search = -1 Then Exit(@error)
   
   While 1
      $File = FileFindNextFile($Search)
      If @error Then ExitLoop
      
      If StringInStr(FileGetAttrib($StartRoot & $File), "D") Then
         ControlSetText("Searching...", "", "Static1", $StartRoot & $File)
         FileSearchSub($StartRoot & $File & "", $Filter, $Files)
      ElseIf StringInStr($File, $Filter[0]) Or StringInStr($File, $Filter[1]) Then
         $Files = $Files & ";" & $StartRoot & $File
      EndIf
   WEnd
   FileClose($Search)
   
   SplashOff()
   
   $Files = StringTrimLeft($Files, 1)
   Return StringSplit($Files, ";")
EndFunc ; FileSearch

Func FileSearchSub($SearchSub, ByRef $Filter, ByRef $Files)
   Local $Search, $File
   
   $Search = FileFindFirstFile($SearchSub & "*.*")
   If $Search = -1 Then Return
   
   While 1
      $File = FileFindNextFile($Search)
      If @error Then ExitLoop
      
      If StringInStr(FileGetAttrib($SearchSub & $File), "D") Then
         ControlSetText("Searching...", "", "Static1", $SearchSub & $File)
         FileSearchSub($SearchSub & $File & "", $Filter, $Files)
      ElseIf StringInStr($File, $Filter[0]) Or StringInStr($File, $Filter[1]) Then
         $Files = $Files & ";" & $SearchSub & $File
      EndIf
   WEnd
   FileClose($Search)
EndFunc ; FileSearchSub oÝ÷ Ûú®¢×®®
Link to comment
Share on other sites

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...