Jump to content
Sign in to follow this  
Simucal

Recursive File Search, with multiple file masks.

Recommended Posts

Simucal

I'm writing a script for work and it involves locating our labs xls and cvs files on all the fixed drives.

The script works fine if I only specify one mask, but if I specify two.. It does not. It returns '2' to the array rather than a list of found files. I'm using w0uters _FileSearch function, which utilizes the dos DIR command.

However, if you type this command in manually it works fine:

dir /B /S C:\*.cvs C:\*.xls

But when I try to run it in this script, I have the problem mentioned above:

#include <Array.au3>

Global $a_DriveList[1],$a_TempList[1],$s_FileList, $i_TotalFiles

$a_DriveList = DriveGetDrive("FIXED")
;_ArrayDisplay($a_DriveList, "Drives")

For $i = 1 To UBound($a_DriveList) - 1
$a_TempSearch = _FileSearch($a_DriveList[$i]&"\*.xls " & $a_DriveList[$i]&"\*.cvs", 1)
$i_TotalFiles += $a_TempSearch[0]
$s_FileList &= _ArrayToString($a_TempSearch, "*",1)
Next
$a_FileList = StringSplit($s_FileList, "*")
$a_FileList[0] = $i_TotalFiles
_ArrayDisplay($a_FileList, "Search 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

So.. I'm not quite sure where I'm going wrong. Maybe someone else can point me in the right direction.


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)

Share this post


Link to post
Share on other sites
evilertoaster

Just from the looks of things I'd guess the problem is more so with the _FileSearch function or how you call it...are you sure that function is supposed allow mutliple searches at the same time?

Share this post


Link to post
Share on other sites
randallc

Hi,

No, it's the quotes; works this way; [i have tested; works here OK; don't really need the quotes or the commas , though, once function fixed!]

$a_TempSearch = _FileSearch('"'&$a_DriveList[$i]&'\*.xls "' &','& '"'&$a_DriveList[$i]&'\*.cvs"', 1)
...
Local $s_Command = ' /c dir '
$s_Command&=$s_Mask&' /B '
If $i_Recurse = 1 Then $s_Command &= ' /S '
Local $s_Buf = '', $i_Pid = Run(@ComSpec & $s_Command  , @WorkingDir, @SW_HIDE, 2+4)
Randall Edited by randallc

Share this post


Link to post
Share on other sites
Simucal

Thanks randallc, you are a true pro!

I missed that :">

Edited by Simucal

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)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.