Void667 Posted February 3, 2014 Posted February 3, 2014 Hi Guys While searching the net i found AutoIT and must say it looks awesome. I just need to learn how to use it Im sorry for my first post being a question but i need some help. My company wants to remove all MP3, AVI, MPEG etc files from all users computers on the domain. I was able to create a login script to pull stats of what computers have these files but now i need something that can delete them automatically for me either via running a script or running a script during logon. Also i need to be able to exclude certain directories. I don't want to delete system and application critical audio files. Can anyone please help me?
orbs Posted February 3, 2014 Posted February 3, 2014 hello Void667, and welcome to AutoIt and to the forum! you say: I was able to create a login script to pull stats of what computers have these files so what stops you from modifying this script to also perform deletion? if this is an AutoIt script, you can post it here and we can build on it rather than make you start scripting from scratch. anyway, to accomplish your task you can get acquainted with a recursive filesystem traverse, like this: TraverseFolder('D:\Users\user\Downloads') ; this is where i have some mp3 files Func TraverseFolder($sPath) $hSearch=FileFindFirstFile($sPath&'\*') ; set-up file pass While True ; check files in path $sFile=FileFindNextFile($hSearch) ; get next file If @error Then ExitLoop ; check for end of files in current folder If StringRight($sFile,4)='.mp3' Then ConsoleWrite($sPath&'\'&$sFile&@CR) ; check for the interesting thing in a file - modify here for your purposes Local $sAttrib = FileGetAttrib($sPath&'\'&$sFile) ; get the file attribute string If StringInStr($sAttrib,'D') Then TraverseFolder($sPath&'\'&$sFile) ; if directory then recourse WEnd FileClose($hSearch) ; Close the search handle EndFunc this is a very basic recursive function, start by reading and understanding what it does, then you can build on it for multiple file types, exclude folders, etc. do ask if something is unclear. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
Void667 Posted February 3, 2014 Author Posted February 3, 2014 Thank you Orbs We used a VB script to pull the details from computers at logon and dump it into a text file: on error resume next Const ForReading = 1 Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") Set WSHNetwork = Createobject("Wscript.Network") strComputerName = WSHNetwork.Computername 'Set objTextFile = objFSO.OpenTextFile ("c:\systemlist.txt", ForWriting) strLog = "\\Server\Logons\Media\"& strComputerName &".txt" Set TS = objFSO.OpenTextFile(strLog,ForWriting,true) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colFiles = objWMIService.ExecQuery _ ("Select * from CIM_DataFile where Extension = 'mp3' OR Extension = 'avi' OR Extension = 'mp4' OR Extension = 'aac' OR Extension = 'wma' OR Extension = 'mkv' OR Extension = 'm4a'") For Each objFile in colFiles 'TS.WriteLine("File Name: " & objFile.Name & "." & objFile.Extension) TS.WriteLine("File Name: " & objFile.Name) Next We can change this to delete BUT we dont want to delete files in C:Windows, C:Program FIles etc etc. The script you gave me works perfectly to list the MP3's in the directory selected. Can i use the TraverseFolder command together with an exclusion like exclude C:Windows? Thank you again for your help
orbs Posted February 3, 2014 Posted February 3, 2014 for your VB script, you can add another where condition to the query, to exclude files beginning with "C:WINDOWS". i can't provide the exact syntax, but i believe it should not be very challenging. another option is to apply this condition in the action part, instead of TS.WriteLine("File Name: " & objFile.Name) for the AutoIt script, a similar condition can be applied, for example if i wouldn't want to delete mp3 files of a-ha, the function would have an extra line when it begins: TraverseFolder('D:\Users\user\Downloads') ; this is where i have some mp3 files Func TraverseFolder($sPath) If StringInStr($sPath,'a-ha') Then Return ; do not continue if this folder has songs by a-ha $hSearch=FileFindFirstFile($sPath&'\*') ; set-up file pass While True ; check files in path $sFile=FileFindNextFile($hSearch) ; get next file If @error Then ExitLoop ; check for end of files in current folder If StringRight($sFile,4)='.mp3' Then ConsoleWrite($sPath&'\'&$sFile&@CR) ; check for the interesting thing in a file - modify here for your purposes Local $sAttrib = FileGetAttrib($sPath&'\'&$sFile) ; get the file attribute string If StringInStr($sAttrib,'D') Then TraverseFolder($sPath&'\'&$sFile) ; if directory then recourse WEnd FileClose($hSearch) ; Close the search handle EndFunc note: the VB script works in a different method than my suggested AutoIt script - instead of traversing the filesystem, it lists the files from WMI query. i think this should prove faster. it can be implemented in AutoIt (for my knowledge i'll tackle that later). Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
water Posted February 3, 2014 Posted February 3, 2014 Use function _FileListToArrayRec to get a list of MP3 files with some directories excluded. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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