Nirvana6 Posted July 17, 2008 Share Posted July 17, 2008 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 ) Link to comment Share on other sites More sharing options...
James Posted July 17, 2008 Share Posted July 17, 2008 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 Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
TehWhale Posted July 17, 2008 Share Posted July 17, 2008 (edited) Some functions you might need:FileFindFirstFileFileFindNextFileStringInStrFileDeleteFileRecycle_FileListToArrayFor/Next loopIf/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 July 17, 2008 by Alienware Link to comment Share on other sites More sharing options...
Nirvana6 Posted July 17, 2008 Author Share Posted July 17, 2008 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 ? Link to comment Share on other sites More sharing options...
Nirvana6 Posted July 17, 2008 Author Share Posted July 17, 2008 i added new keywords - works perfectly muttley is there a way to check if something found is a file or a folder ? Link to comment Share on other sites More sharing options...
James Posted July 17, 2008 Share Posted July 17, 2008 (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 July 17, 2008 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Nirvana6 Posted July 17, 2008 Author Share Posted July 17, 2008 Thanks again :-) ! I will post the code tomorrow (is 10:30 PM here muttley and i'm sleepy (sorry for offtopic) ) Link to comment Share on other sites More sharing options...
James Posted July 17, 2008 Share Posted July 17, 2008 Thanks again :-) !I will post the code tomorrow (is 10:30 PM here and i'm sleepy (sorry for offtopic) )Any time muttleyOk, I look forward to seeing it! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Paulie Posted July 17, 2008 Share Posted July 17, 2008 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" Link to comment Share on other sites More sharing options...
James Posted July 17, 2008 Share Posted July 17, 2008 That is true. So how would you search through the list of words in a filename then? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Paulie Posted July 17, 2008 Share Posted July 17, 2008 That is true. So how would you search through the list of words in a filename then?I'm just talking about this function here: Func IsDirectory($FileName) $IsDir = FileGetAttrib($FileName) If StringInStr($IsDir,"D") Then ; NOTE: The StringInStr Return True Else Return False EndIf EndFunc Link to comment Share on other sites More sharing options...
James Posted July 17, 2008 Share Posted July 17, 2008 Ahh right. So you would still use StringInStr() for the searching of "explicit" words? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted July 17, 2008 Share Posted July 17, 2008 (edited) Recursive file search reference here:http://www.autoitscript.com/forum/index.ph...rsivefilesearchexpandcollapse popup;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 July 17, 2008 by weaponx Link to comment Share on other sites More sharing options...
James Posted July 17, 2008 Share Posted July 17, 2008 Nice! Just learnt something new there muttley Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Nirvana6 Posted July 17, 2008 Author Share Posted July 17, 2008 Thanks to all of you muttley ! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now