Jump to content

Recommended Posts

Posted (edited)

decided to gave it its own post since it was faster then anything i have seen.

Func _FileSearch($s_Mask = '', $i_Recurse = 1)
    Local $s_Command = ' /c dir /B "'
    If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'
    Local $s_Buf = '', $i_Pid = Run(@ComSpec & $s_Command & $s_Mask & '"', @WorkingDir, @SW_HIDE, 2+4)
    ProcessSetPriority($i_Pid, 5)
    While Not @error
        $s_Buf &= StdoutRead($i_Pid)
    WEnd
    $s_Buf = StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)
    ProcessClose($i_Pid)
    If UBound($s_Buf) = 2 AND $s_Buf[1] = '' Then SetError(1)
    Return $s_Buf
EndFunc  ;==>_FileSearch

new: added optional sub search

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Posted (edited)

Here is a text file search using similar algorithm.

Func _TextSearch($s_Mask = "",$text = "",$recursive = 0)
    Local $s_Buf = ""
    Dim $array[1]
    
    If $recursive Then
        $i_Pid = Run(@ComSpec & ' /c findstr /I /M /P /S /C:"' & $text & '" "' & $s_Mask & '"',@WorkingDir,@SW_HIDE,2)
    Else
        $i_Pid = Run(@ComSpec & ' /c findstr /I /M /P /C:"' & $text & '" "' & $s_Mask & '"',@WorkingDir,@SW_HIDE,2)
    EndIf
    
    While Not @error
        $s_Buf &= StdoutRead($i_Pid)
    WEnd
    
    return StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)
EndFunc
Edited by livewire
Posted

Yep wOuter, these are the fastest that I've seen so far. I figured out why I got bad data comparing the scripts...I had "Indexing Service" turned off.

Note: Make sure "Indexing service" is enabled for best results.

-Livewire

  • 8 months later...
Posted

This is damn fast. Was exactly what I was looking for. Other scripts using _FileFindFirst/Next were prohibitively slow.

Thanks w0uter

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
  • 2 months later...
Posted

Can anyone please tell me why this doesn't work for me?

$var = _FileSearch('C:\*.bat')

dim $results
For $i = 1 to $var[0]
$results &= $var[$i] & @CRLF
Next

msgbox(0, 'Test', $results)

Func _FileSearch($s_Mask = '', $i_Recurse = 1)
    Local $s_Command = ' /c dir /B "'
    If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'
    Local $s_Buf = '', $i_Pid = Run(@ComSpec & $s_Command & $s_Mask & '"', @WorkingDir, @SW_HIDE, 2+4)
    ProcessSetPriority($i_Pid, 5)
    While Not @error
        $s_Buf &= StdoutRead($i_Pid)
    WEnd
    $s_Buf = StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)
    ProcessClose($i_Pid)
    If UBound($s_Buf) = 2 AND $s_Buf[1] = '' Then SetError(1)
    Return $s_Buf
EndFunc ;==>_FileSearch

It's basically the exact code that's pasted above, just using a msgbox() rather than consolewrite().

It should return 3 batch files, but I don't get anything returned. Here's what command shows when I run it manually:

C:\>cmd /c dir /B /S c:\*.bat
c:\AUTOEXEC.BAT
c:\Program Files\Vim\vimtutor.bat
c:\WINDOWS\system32\MsDtc\Trace\msdtcvtr.bat

So what am I doing wrong? I'm running AutoIt 3.2.0.1. Thanks.

Posted

Nevermind. It figures that I figure it out as soon as I post the question. The ProcessSetPriority() line seems to be causing the problem. When I remove that line, it works everytime. If I leave it in, it works about 1 out of every 10 times. Weird.

Anyway, just a heads up if anyone else has a similar problem.

Posted (edited)

Change the While Not error to Do...Until @error as the previous is also checking ProcessSetPriority() for error which you do not want.

Removing ProcessSetPriority() altogether is a much better idea as I see it doing little anyway.

Edited by MHz
Posted

I had the same problems a long time ago, I removed the Process Priority line as well.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
  • 5 weeks later...
Posted

I have use this to write a small file search:

; start directory
const $programpath = @SystemDir

; Search recursive?
; @param  bool  True/False
Local $SearchRecurse = False

; example - search this files
Local $DateiArray[4]
$DateiArray[0] = "eula.txt"; exist
$DateiArray[1] = "foo.dll" ; not exist
$DateiArray[2] = "hid.dll" ; exist
$DateiArray[3] = "ias.mdb" ; exist in system32/ias/


Local $DateiGefunden
For $i = 0 to UBound($DateiArray) -1
  Local $var = _FileSearch($programpath & '\' & $DateiArray[$i], $SearchRecurse)
  if $var[1] <> '' Then $DateiGefunden &= $DateiArray[$i] & @LF
Next

MsgBox(0, "File found!", 'This files found: '& @CRLF&@CRLF & $DateiGefunden )

; File Search
;
; @param  string  file name or file mask (*.txt)
; @param  bool  True/False
; @return array   [0] - ?, [1] - file name
Func _FileSearch($s_Mask = '', $i_Recurse = 1)
    Local $s_Command = ' /c dir /B "'
    If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'
    Local $s_Buf = '', $i_Pid = Run(@ComSpec & $s_Command & $s_Mask & '"', @WorkingDir, @SW_HIDE, 2+4)
;~   ProcessSetPriority($i_Pid, 5)
    While Not @error
      $s_Buf &= StdoutRead($i_Pid)
    WEnd
    $s_Buf = StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)
;~   ProcessClose($i_Pid)
    If UBound($s_Buf) = 2 AND $s_Buf[1] = '' Then SetError(1)
    Return $s_Buf
EndFunc ;==>_FileSearch

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
  • Recently Browsing   0 members

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