Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

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
0
pbollard
Asked:
pbollard
  • 4
  • 3
1 Solution
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now