Jump to content

Running _FileSearch in all fixed drives


SoulBlade
 Share

Recommended Posts

Hi!

Using code available in this forum, i'm trying to use _FileSearch function in all fixed drives.

Here's the code i'm come up to:

CODE
Func _FileSearch($s_Mask = '', $i_Recurse = 1)

Local $s_Command = ' /c dir /B "'

If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'

$dc = DriveGetDrive( "fixed" )

For $i = 1 to $dc[0]

Local $s_Buf = '', $i_Pid = Run(@ComSpec & $s_Command & $s_Mask & '"', $dc, @SW_HIDE, 2+4)

next

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

I'm going nuts!

:)

Link to comment
Share on other sites

What exactly is the problem?

All I see is a typo:

Func _FileSearch($s_Mask = '', $i_Recurse = 1)

Local $s_Command = ' /c dir /B "'

If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'

$dc = DriveGetDrive( "fixed" )

For $i = 1 to $dc[0]

Local $s_Buf = '', $i_Pid = Run(@ComSpec & $s_Command & $s_Mask & '"', $dc, @SW_HIDE, 2+4)

next

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

Should be $dc[$i]
Link to comment
Share on other sites

What exactly is the problem?

All I see is a typo:

Should be $dc[$i]

You're right! That little typo cost me 30m! :)

I changed that line to:

Local $s_Buf = '', $i_Pid = Run(@ComSpec & $s_Command & $s_Mask & '"', $dc[$i] &"\", @SW_HIDE, 2+4)

but the function only returns files from the last fixed disk.

Any ideias?

Thanks for your help!

:)

Link to comment
Share on other sites

Hi!

Using code available in this forum, i'm trying to use _FileSearch function in all fixed drives.

Here's the code i'm come up to:

CODE
Func _FileSearch($s_Mask = '', $i_Recurse = 1)

Local $s_Command = ' /c dir /B "'

If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'

$dc = DriveGetDrive( "fixed" )

For $i = 1 to $dc[0]

Local $s_Buf = '', $i_Pid = Run(@ComSpec & $s_Command & $s_Mask & '"', $dc, @SW_HIDE, 2+4)

next

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

I'm going nuts!

:)

#include <Array.au3>
_ArrayDisplay(_FileSearch('',  1), "_ArrayDisplay() Test")
Func _FileSearch($s_Mask = '', $i_Recurse = 1)
Local $s_Command = ' /c dir /B "'
If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'
$dc = DriveGetDrive( "fixed" )
$s_Buf = ''
For $i = 1 to $dc[0]  Step 1
$i_Pid = Run(@ComSpec & $s_Command & $s_Mask & $dc[$I] & "\", "", @SW_HIDE, 2+4)
While 1
$s_BufX = StdoutRead($i_Pid)
If @error Then ExitLoop
$s_Buf &= $s_BufX
WEnd 
next
$s_Buf = StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)
If UBound($s_Buf) = 2 AND $s_Buf[1] = '' Then SetError(1)
Return $s_Buf
EndFunc;==>_FileSearch
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

Thanks Nahuel and Wolf9228!

Using Wolf9228 code, i'm trying to delete all *.AAA files found by the _Filesearch function:

CODE
AutoItSetOption("TrayIconHide", 1)

#include <GUIConstants.au3>

#include <Array.au3>

GUICreate("DiskCleaner 1.0", 250, 80)

GUISetIcon("diskcleaner.ico", 0)

$run= GUICtrlCreateButton("RUN", 90, 30, 80, 30)

GUISetState()

Do

$msg = GUIGetMsg()

select

case $msg= $Run

GUICtrlSetState ($run, $GUI_DISABLE)

$fil1 = _FileSearch('*.aaa')

For $ir = 1 to $fil1[0]

FileSetAttrib ( $fil1[$ir], "-R")

FileDelete($fil1[$ir])

next

Case $msg= $GUI_EVENT_CLOSE

exit

EndSelect

Until $msg = $GUI_EVENT_CLOSE

Func _FileSearch($s_Mask = '', $i_Recurse = 1)

Local $s_Command = ' /c dir /B "'

If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'

$dc = DriveGetDrive( "fixed" )

$s_Buf = ''

For $i = 1 to $dc[0] Step 1

$i_Pid = Run(@ComSpec & $s_Command & $s_Mask & $dc[$I] & "\", "", @SW_HIDE, 2+4)

While 1

$s_BufX = StdoutRead($i_Pid)

If @error Then ExitLoop

$s_Buf &= $s_BufX

WEnd

next

$s_Buf = StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)

If UBound($s_Buf) = 2 AND $s_Buf[1] = '' Then SetError(1)

Return $s_Buf

EndFunc;==>_FileSearch

Unfortanely i can't make it work.

:)

Any ideias?

Many thanks! :)

Edited by SoulBlade
Link to comment
Share on other sites

Thanks Nahuel and Wolf9228!

Using Wolf9228 code, i'm trying to delete all *.AAA files found by the _Filesearch function:

CODE
AutoItSetOption("TrayIconHide", 1)

#include <GUIConstants.au3>

#include <Array.au3>

GUICreate("DiskCleaner 1.0", 250, 80)

GUISetIcon("diskcleaner.ico", 0)

$run= GUICtrlCreateButton("RUN", 90, 30, 80, 30)

GUISetState()

Do

$msg = GUIGetMsg()

select

case $msg= $Run

GUICtrlSetState ($run, $GUI_DISABLE)

$fil1 = _FileSearch('*.aaa')

For $ir = 1 to $fil1[0]

FileSetAttrib ( $fil1[$ir], "-R")

FileDelete($fil1[$ir])

next

Case $msg= $GUI_EVENT_CLOSE

exit

EndSelect

Until $msg = $GUI_EVENT_CLOSE

Func _FileSearch($s_Mask = '', $i_Recurse = 1)

Local $s_Command = ' /c dir /B "'

If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'

$dc = DriveGetDrive( "fixed" )

$s_Buf = ''

For $i = 1 to $dc[0] Step 1

$i_Pid = Run(@ComSpec & $s_Command & $s_Mask & $dc[$I] & "\", "", @SW_HIDE, 2+4)

While 1

$s_BufX = StdoutRead($i_Pid)

If @error Then ExitLoop

$s_Buf &= $s_BufX

WEnd

next

$s_Buf = StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)

If UBound($s_Buf) = 2 AND $s_Buf[1] = '' Then SetError(1)

Return $s_Buf

EndFunc;==>_FileSearch

Unfortanely i can't make it work.

:)

Any ideias?

Many thanks! :)

#include <GUIConstants.au3>
#include <Array.au3>

_ArrayDisplay(_FileSearch(1,"",'*au3' ,1)  , "Search au3 Type in fixed drives")
_ArrayDisplay(_FileSearch(1,"",'*.' ,1) , "Search only dir in fixed drives")

_ArrayDisplay(_FileSearch(0,@MyDocumentsDir,'*.' ,1)   , "Search only dir in MyDocumentsDir")
_ArrayDisplay(_FileSearch(0,@MyDocumentsDir,'*au3' ,1)   , "Search au3 Type in MyDocumentsDir")



;For $ir = 1 to $fil1[0] Step 1
;$fil2 = FileGetShortName($fil1[$ir])
;Run("attrib.exe " & $fil2 & " -R"  , "",@SW_HIDE)
;if StringInStr($fil1[$ir], ".") then 
;FileDelete($fil1[$ir])
;else 
;DirRemove($fil1[$ir], 1)
;endif 
;next



Func _FileSearch($fixedDrives =1, $PATCHDIR = @MyDocumentsDir, $Type ='*' ,$i_Recurse = 1)
Local $s_Command = ' /c dir /B "'
If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'
$s_Buf = ''
if $fixedDrives = 1 then 
$dc = DriveGetDrive( "fixed" )
For $i = 1 to $dc[0] Step 1
$i_Pid = Run(@ComSpec & $s_Command & $dc[$I] & "\" & $Type, "", @SW_HIDE, 2+4)
While 1
$s_BufX = StdoutRead($i_Pid)
If @error Then ExitLoop
$s_Buf &= $s_BufX
WEnd
next
else 
if  StringRight($PATCHDIR, 1) <> "\" then $PATCHDIR = $PATCHDIR & "\"
$i_Pid = Run(@ComSpec & $s_Command & $PATCHDIR  & $Type, "", @SW_HIDE, 2+4)
While 1
$s_BufX = StdoutRead($i_Pid)
If @error Then ExitLoop
$s_Buf &= $s_BufX
WEnd
endif 
$s_Buf = StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)
If UBound($s_Buf) = 2 AND $s_Buf[1] = '' Then SetError(1)
Return $s_Buf
EndFunc;==>_FileSearch
Edited by wolf9228

صرح السماء كان هنا

 

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