Jump to content

Search for file


 Share

Recommended Posts

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.

Link to comment
Share on other sites

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