Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBSCRIPT Delete All Files/Folders in a subfolder (wildcard)

Status
Not open for further replies.

kasandoro

IS-IT--Management
Feb 11, 2003
11
US
Alright, here's what I have so far:

Code:
 On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Directory WHERE FileName LIKE '%kazaa%'OR FileName LIKE '%imesh' OR FileName LIKE '%blubster%' OR FileName LIKE '%emule'")
For Each objItem in colItems
    'WScript.Echo(objItem.Name)
   objitem.DeleteFolder
Next

I'm trying to find any and all folders on the drive that are named %Kazaa%, %imesh, %blubster% or %emule and delete the folders and all the contents. This script deletes all the files in the root of the folder if it finds the folder, but leaves the folder structure. Is there any way to delete the whole folder structure?
 
Any ideas at all?

I had a look at some of the recursive delete commands posted here, but I couldn't get any of them to work.
 
And what about this ?
objitem.Delete

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That does the same thing...leaves the folder structure and the files in the child folders under the root intact.
 
Comment out the On Error Resume Next to discover what happens.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
No errors or anything...the script processes just fine. I suspect it's because the folders aren't empty...
 
Have a look here (Err 14)
Why not using the FileSystemObject (aka fso) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top