Jump to content

Recommended Posts

Posted

This script should perform a computer scan for some keywords in all the computer and delete the files/folders found containing one or more of the keywords.

muttley

As I said i need some tips because I'm a noob :).

Please excuse my bad english (if it's present :()

Posted

Something like this?

#include <File.au3>
#include <Array.au3>

RemoveFiles("MyMusic.mp3")

Func RemoveFiles($FileName, $sPath = @ScriptDir, $sFilter = "*")
    $fList = _FileListToArray($sPath, $sFilter)
; _ArrayDisplay($fList)
    If _ArraySearch($fList, $FileName) Then
        FileChangeDir($sPath)
        FileDelete($FileName); Delete file if match found!
        If Not @error Then ConsoleWrite("Deleted: " & $FileName & @CRLF)
    EndIf
EndFunc
Posted (edited)

Some functions you might need:

  • FileFindFirstFile
  • FileFindNextFile
  • StringInStr
  • FileDelete
  • FileRecycle
  • _FileListToArray
  • For/Next loop
  • If/Then

@JamesBrooks, I think he's looking for in the name of the file, to have stuff like: "Shit", "Fuck", "Bitch", "Ass", and other curse words, then delete that file and move on.

Edited by Alienware
Posted

Thanks! muttley

I played with those :

* FileFindFirstFile

* FileFindNextFile

* StringInStr

* FileDelete

* FileRecycle

* _FileListToArray

* For/Next loop

* If/Then

these days... :)

Now...

i guess that all i need to do now is to add more keywords...

Something like that :

#include <File.au3>
#include <Array.au3>

RemoveFiles("MyMusic.mp3")
RemoveFiles("Test1.mp3")

Func RemoveFiles($FileName, $sPath = @ScriptDir, $sFilter = "*")
    $fList = _FileListToArray($sPath, $sFilter)
; _ArrayDisplay($fList)
    If _ArraySearch($fList, $FileName) Then
        FileChangeDir($sPath)
        FileDelete($FileName); Delete file if match found!
        If Not @error Then ConsoleWrite("Deleted: " & $FileName & @CRLF)
    EndIf
EndFunc

right ?:(

Posted (edited)

Sure is.

Func IsDirectory($FileName)
    $IsDir = FileGetAttrib($FileName)
    If $IsDir = "D" Then
        Return True
    Else
        Return False
    EndIf
EndFunc

@Alienware, an array with keywords looped will work muttley

Global $WhatWords[3] = ["Shit", "Fuck", "Bitch"]; Add more words

For $i = 0 to UBound($WhatWords) - 1
    RemoveFiles($WhatWords[$i], @ScriptDir, ".mp3")
Next

Woops, fixed the big with the array size being to big or small.

Edit again: You could also use StringInStr() to check if any of the files listed contained those words.

Edited by JamesBrooks
Posted

Sure is.

-[clip]-

Woops, fixed the big with the array size being to big or small.

Edit again: You could also use StringInStr() to check if any of the files listed contained those words.

I would use StringInStr() For the FileGetAttrib() check Because the file could be a "hidden directory" or a "system directory" or something and FileGetAttrib() would return would be "HD" or "SD"
Posted (edited)

Recursive file search reference here:

http://www.autoitscript.com/forum/index.ph...rsivefilesearch

;Dirty words seperated by pipe symbol
$BadWords = "fuck|shit|piss|cunt|cock|yarbles|schwanzstucker"

;Search
$array = RecursiveFileSearch(@DesktopDir, "(?i)("&$BadWords&")", "", 1)
For $X = 1 to $array[0]
    ConsoleWrite('['&$X&']: ' & $array[$X] & @CRLF)
    ;FileDelete($array[$X])
Next

Func RecursiveFileSearch($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = True, $RFSdepth = 0)

    ;Ensure starting folder has a trailing slash
    If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\"

    If $RFSdepth = 0 Then
        ;Get count of all files in subfolders for initial array definition
        $RFSfilecount = DirGetSize($RFSstartDir, 1)

        ;File count + folder count (will be resized when the function returns)
        Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1]
    EndIf

    $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*")
    If @error Then Return

    ;Search through all files and folders in directory
    While 1
        $RFSnext = FileFindNextFile($RFSsearch)
        If @error Then ExitLoop
        
        ;If folder and recurse flag is set and regex matches
        If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then

            If $RFSrecurse And StringRegExp($RFSnext, $RFSFolderpattern, 0) Then
                RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1)
                If $RFSFlag <> 1 Then
                    ;Append folder name to array
                    $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
                    $RFSarray[0] += 1
                EndIf
            EndIf
        ElseIf StringRegExp($RFSstartDir & $RFSnext, $RFSFilepattern, 0) And $RFSFlag <> 2 Then
            ;Append file name to array
            $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
            $RFSarray[0] += 1
        EndIf
    WEnd
    FileClose($RFSsearch)

    If $RFSdepth = 0 Then
        ReDim $RFSarray[$RFSarray[0] + 1]
        Return $RFSarray
    EndIf
EndFunc   ;==>RecursiveFileSearch
Edited by weaponx

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
×
×
  • Create New...