Sign in to follow this  
Followers 0
Void667

Delete MP3 off remote computers

5 posts in this topic

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?

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Use function _FileListToArrayRec to get a list of MP3 files with some directories excluded.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0