VBscript for searching for mp3's and deleting them

vbscript code to search for mp3's and delete them, or any similar vbscript if possible
pbollardAsked:
Who is Participating?
 
yehudahaCommented:
what you asked for search for mp3 file and delete them
i added a done message so you know when the script actually finished
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile where Extension = 'mp3'")
For Each objFile in colFiles
    objFile.Delete
Next
msgbox "done"

Open in new window

0
 
yehudahaCommented:
here
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile where Extension = 'mp3'")
For Each objFile in colFiles
    objFile.Delete
Next

Open in new window

0
 
pbollardAuthor Commented:
could you explain what this code does and if there is anything i have to modify if you could please. when i create it and open the file nothing appears to be happening.  thank you
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
pbollardAuthor Commented:
should anything pop-up on screen to say that mp3 files have been deleted?or does it just run in the background?thank for your help
0
 
pbollardAuthor Commented:
sorry, working fine...thanks very much for your help
0
 
yehudahaCommented:
you can run this one from the command line like this :

cscript ScriptName.vbs

and it will echo the file names deleting
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile where Extension = 'mp3'")
For Each objFile in colFiles
    wscrip.echo objFile.Name & " Deleted"
    objFile.Delete
Next
msgbox "done"

Open in new window

0
 
pbollardAuthor Commented:
thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.