Hi,
I’m looking for a script, that I can run locally on one of my servers, which will delete a folder and any subfolders contained within it. The top level folder and its subfolders will contain files, and possibly further subfolders. I also require the ability to delete subfolders without knowing their name.
I have found the following vbs script on the Windows 2000 Technet Scripting Guide, which uses WMI…
*****************************
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!” & strComputer & “rootcimv2”)
Set colFolders = objWMIService.ExecQuery _
(“SELECT * FROM Win32_Directory WHERE Name = ‘c:test'”)
For Each objFolder in colFolders
errResults = objFolder.Delete
Wscript.Echo errResults
Next
*****************************
This works just fine on the top level folder (C:test) even when it contains files, but if it contains a subfolder the script fails with an error of 14 (folder not empty).
Can anyone offer a solution, or point me in the right direction? This is such a basic administrative task, but I can find no immediate solution?
TIA,