Jump to content

searching for a file and deleting it


Recommended Posts

This do you?

Search ("C:\","advapi32.dll");replace with your search directory and file required

Func Search($current,$toFind)
    If StringRight($current,1) = "\" then $current = StringTrimRight($current,1)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

            IF $file = $toFind then Msgbox(0,"File found", $current & "\" & $file); you could add it to an array delete it or whatever else you wanted to do with it here
                
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            Search($current & "\" & $file, $toFind)
            
        EndIf
        
    WEnd
    FileClose($search)

EndFunc
Link to comment
Share on other sites

@ ChrisL

hey! Thanks man, you are doing good.

one more thing: can i add more dirs/files?

Your lucky I'm feeling hypo today muttley

Local $filesToFind[4] = [3,"advapi32.dll","advpack.dll","audiodev.dll"]

Search (@windowsDir,$filesToFind);replace with your search directory and file required
Search (@DesktopDir,$filesToFind)
Search ("D:\",$filesToFind)



Func Search($current,ByRef $toFind)
    If StringRight($current,1) = "\" then $current = StringTrimRight($current,1)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            
            If IsArray($toFind) then 
                For $i = 1 to Ubound($toFind) -1
                    IF $file = $toFind[$i] then Msgbox(0,"File found", $current & "\" & $file); you could add it to an array delete it or whatever else you wanted to do with it here
                Next
            Else
                
                IF $file = $toFind then Msgbox(0,"File found", $current & "\" & $file); you could add it to an array delete it or whatever else you wanted to do with it here
            EndIf
            
                
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            Search($current & "\" & $file, $toFind)
            
        EndIf
        
    WEnd
    FileClose($search)

EndFunc
Link to comment
Share on other sites

For recursive search search forum for _FileList2ArrayEx()

i got only the current thread by searching this word. _FileList2ArrayEx()

nothing exists in this forum like this.

[font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php
$Life = "Happy"
If @Error Then
$Life = "Risk"
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...