Sign in to follow this  
Followers 0
Mat

small Search

1 post in this topic

Searces your entire home drive (or a directory) of your computer, and pretty quickly too (does mine in 20 secs, and my computers ancient!)

Basically, a bit of fun to see how fast it would go in autoit, and there is not a huge difference between my times and the M$ search assistant one. I'll accept that thats got a lot more options, but the ideas there. I am going to be using this script in a project of mine for finding individual executables by name, and its working fine there.

2 functions:

* _Find - Searches until match is found, then returns it.

* _FindAll - Keeps searching and returns a @CRLF string of all the files found

Func _Find ($s, $d = @HomeDrive)
   If StringRight ($d, 1) <> "\" Then $d &= "\"
   Local $h = FileFindFirstFile ($d & "*")
   If $h = -1 Then Return 0
   while 1
      $t = FileFindNextFile ($h)
      If $t = $s Then Return $d & $t
      $t = $d & $t
      If @Error Then Return 0 * FileClose ($h)
      If StringInStr (FileGetAttrib ($t), "D") Then
         $tmp = _Find ($s, $t)
         If $tmp <> "0" Then Return $tmp
         ContinueLoop
      EndIf
   WEnd
   FileClose ($h)
   Return 0
EndFunc ; ==> _Find

Func _FindAll ($s, $d = @HomeDrive)
   If Not IsDeclared ("sRet") Then
      Static $sRet = ""
   EndIf
   If StringRight ($d, 1) <> "\" Then $d &= "\"
   Local $h = FileFindFirstFile ($d & "*")
   If $h = -1 Then Return ""
   while 1
      $t = FileFindNextFile ($h)
      If @Error Then ExitLoop
      If $t = $s Then $sRet &= @CRLF & $d & $t
      $t = $d & $t
      If StringInStr (FileGetAttrib ($t), "D") Then $tmp = _FindAll ($s, $t)
   WEnd
   FileClose ($h)
   Return $sRet
EndFunc ; ==> _FindAll

For an example just use:

MsgBox (0, "", _FindAll ("test.au3"))
If you are as messy as I am then the result will be very long. If you want to change the initial directory then just add a second parameter.

Mat

Share this post


Link to post
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
Sign in to follow this  
Followers 0