Using WMI to delete Files or Folders
Using WMI in DesktopX
Monday, July 7, 2008 by Vad_M | Discussion: DesktopX Tutorials
Just two simple examples:
1. Delete a File:
Enter the path to your file here:
file = "C:\Users\Vadim\AppData\Local\Stardock\SD Gadgets\RSS Reader\Feeds\N4G.com"
Set objWMI = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set objFIL = objWMI.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='"& file &"'} Where "&"ResultClass = CIM_DataFile")
For Each item In objFIL
item.Delete
Next
Set objFIL = nothing : Set objWMI = nothing
1. Delete a Folder:
Enter the path to your folder here:
folder = "C:\Users\Vadim\AppData\Local\Stardock\SD Gadgets\RSS Reader\Feeds"
folder = Replace(folder, "\", "\\") '<== it's need to replace the path to foler...
Set objWMI = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set objFOL = objWMI.ExecQuery ("Select * from Win32_Directory where Name = '" & folder & "'")
For Each item In objFOL
item.Delete
Next
Set objFOL = nothing : Set objWMI = nothing
Long ago I have used FSO for this. But it seems to me that WMI work more quickly.
Best Regards.
Reply #3 Tuesday, July 8, 2008 7:19 AM
I didn't measure it specially. However I can see that the speed is very, very high.
Recently I have tested a several ways to search files in a computer (I worked on a tool for global searching for media information and used FSO, WSH and WMI). May tell you that nothing works so quickly as WMI! This is FANTASTIC!
WMI is the Windows Management Instrumentation: About WMI
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!







Reply #1 Monday, July 7, 2008 10:12 PM
I found the ShellApp with dialog's disabled is quicker than FSO also. How's WMI speed on folder collections?