Jump to content
Sign in to follow this  
SoulBlade

Running _FileSearch in all fixed drives

Recommended Posts

SoulBlade

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!

:)

Share this post


Link to post
Share on other sites
Nahuel

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]

Share this post


Link to post
Share on other sites
SoulBlade

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!

:)

Share this post


Link to post
Share on other sites
Nahuel

Could you post an example? I'm trying but I can't get it to work...

Share this post


Link to post
Share on other sites
wolf9228

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

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

 

Share this post


Link to post
Share on other sites
SoulBlade

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

Share this post


Link to post
Share on other sites
SoulBlade

I think this;

$i_Pid = Run(@ComSpec & $s_Command & $s_Mask & $dc[$i] & "\", "", @SW_HIDE, 2+4)oÝ÷ Ù+©¦¶Þjëh×6$i_Pid = Run(@ComSpec & $s_Command & $dc[$i] & "\" & $s_Mask, "", @SW_HIDE, 2+4)
Yes it worked!

:)

Many thanks Aslani!

Share this post


Link to post
Share on other sites
wolf9228

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

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

 

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  

×