Jump to content
Sign in to follow this  
qazwsx

Search for file

Recommended Posts

qazwsx

Here is my attempt at a function to search the entire computer for all of a certain type of file:

Func _findBats ($folder)
    
    local $search = FileFindFirstFile ("*.txt")
    If $search <> -1 Then;looks to bat files
        While 1
            local $file = FileFindNextFile ($search)                    
            If @error = 1 then ExitLoop;no more files       
            MsgBox (0, "", $file)   
        WEnd
    EndIf
    
    
    $folders = _FileListToArray ($folder, "*", 2);gets other folders and checks them
    If @error = 4 then Return
    
    For $i = 1 to $folders[0]
        _findBats ($folder & $folders[$i] & "\")
    Next    
EndFunc

It returns the same to file names over and over again. Neither of which are in my c drive. Any help is appreciated.

Share this post


Link to post
Share on other sites
AdmiralAlkex

You forgot to tell FileFindFirstFile() which folder it should search, try this:

#Include <File.au3>

_findBats("C:\")

Func _findBats ($folder)
    
    local $search = FileFindFirstFile ($folder & "*.txt")
    If $search <> -1 Then;looks to bat files
        While 1
            local $file = FileFindNextFile ($search)                    
            If @error = 1 then ExitLoop;no more files       
;~           MsgBox (0, "", $file)  
            ConsoleWrite($file & @CRLF)
        WEnd
    EndIf
    
    
    $folders = _FileListToArray ($folder, "*", 2);gets other folders and checks them
    If @error = 4 then Return
    
    For $i = 1 to $folders[0]
        _findBats ($folder & $folders[$i] & "\")
    Next    
EndFunc

EDIT: You forgot to close the search handle! You should add FileClose($search) after the while loop!

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites
qazwsx

ohh thank you, not sure how i missed that, and good call on consolewrite

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  

×