Jump to content

Search Func


Recommended Posts

So here is my code...

$SearchPath=$ScanFolder&"\*"
GenericSearch ( $CDir , $SearchPath )
$CDir=StringSplit( $CDir, "|")
For $c=1 to $CDir[0] Step 1
    $File3=$ScanFolder&"\"&$CDir[$c]
    $Attrib=FileGetAttrib ( $File3 )
    If StringInStr($Attrib, "D") Then
        $SearchPath=$File3&"\*"
        GenericSearch ( $DDir, $SearchPath)
        $DDir=StringSplit( $DDir, "|")
        For $d=1 to $DDir[0] Step 1
            $File4=$ScanFolder&"\"&$CDir[$c]&"\"&$DDir[$d]
            $Attrib=FileGetAttrib ( $File4 )
            If StringInStr($Attrib, "D") Then
                FileWriteLine ( $Log1, $DDir[$d] )
                FileWriteLine ( $Log2, $File4 )
            EndIf
        Next
    EndIf
Next

Func GenericSearch ( ByRef $a, ByRef $b )
Local $File
$Search = FileFindFirstFile($b)
If $Search = -1 Then
    Exit
EndIf
While 1
    $File = FileFindNextFile($Search) 
    If @error Then ExitLoop
    If $File="." Then ContinueLoop
    If $File=".." Then ContinueLoop
    If $File="Config" Then ContinueLoop 
    $a=$a&"|"&$File
WEnd
$a=StringReplace ( $a, "|", "", 1 )
FileClose($Search)
EndFunc

This one drives me nuts.

Sometimes the output is ok. One minute later it isn't.

What the **** is wrong with it?

I even get no output for Log1 even though Log2 is filled.

But Log1 is just the "last" dir, Log2 is the hole path. :(

Link to comment
Share on other sites

You had a few mistakes. I changed it some. I didn't really test it tho, but it should give you some ideas.

$SearchPath = $ScanFolder & "\*"
$CDir = GenericSearch($SearchPath)
$CDir = StringSplit($CDir, "|")

For $c = 1 To $CDir[0]
    $File3 = $ScanFolder & "\" & $CDir[$c]
    $Attrib = FileGetAttrib($File3)
    
    If StringInStr($Attrib, "D") Then
        $SearchPath = $File3 & "\*"
        $DDir = GenericSearch($SearchPath)
        $DDir = StringSplit($DDir, "|")
        
        For $d = 1 To $DDir[0] Step 1
            $File4 = $ScanFolder & "\" & $CDir[$c] & "\" & $DDir[$d]
            $Attrib = FileGetAttrib($File4)
            
            If StringInStr($Attrib, "D") Then
                FileWriteLine($Log1, $DDir[$d])
                FileWriteLine($Log2, $File4)
            EndIf
        Next
    EndIf
Next

Func GenericSearch($path)
    Local $File
    
    $Search = FileFindFirstFile($b)
    If $Search = -1 Then
        Exit
    EndIf
    
    While 1
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        If $File = "." Then ContinueLoop
        If $File = ".." Then ContinueLoop
        If $File = "Config" Then ContinueLoop
        $a = $a & "|" & $File
    WEnd
    
;~     $a = StringReplace($a, "|", "", 1)
    FileClose($Search)
    return $a
EndFunc  ;==>GenericSearch

Edited by steveR
AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
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...