Hi

I'm Looking for somehelp with a VBscript.

My Scenario:-

We have some 500 machines on which users have a folder {ex: game} which has sub folders and files in it. I'm looking for script which will search for Executable game.exe in the 'game' folder and if located delete the "game" folder and subfolders and files in it.

so the problem is this folder is not in a fixed location. I mean it can be any where in the C drive and also the name of the 'game' folder is different on some machines.

I have found a script to search for this game.exe and delete if found but i want to delete the entire directory of game.exe

strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
find_file "game","exe"
Function find_file(filename, extension)
Set colItems = objWMIService.ExecQuery("SELECT * FROM CIM_DataFile WHERE Drive = 'C:' AND FileName='" & filename & "' AND Extension='" & extension & "'",,48)
For Each objItem in colItems
WScript.Echo "Found " & objItem.Name & " in " & objItem.Drive & objItem.Path
objItem.Delete
Next
End Function

Any help is much appreciated and thank you for your time.

Thanks
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

2
Take a look at the ParentFolder Property.

I think that'll point you in the right direction.

http://www.devguru.com/technologies/vbscript/quickref/file.html
Answered 04/05/2011 by: dchristian
Red Belt

Please log in to comment
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Thank you david

one question does the ParentFolder property return the parent folder of my script or file?
Answered 04/05/2011 by: acidburn777
Yellow Belt

Please log in to comment
0
It'll be the parent folder of the file (objItem).
Answered 04/05/2011 by: dchristian
Red Belt

Please log in to comment
0
objFSO.GetParentFolderName(objItem.Name) did the job for me.

Really Appreciate your help

Thank You so much
Answered 04/05/2011 by: acidburn777
Yellow Belt

Please log in to comment
0
Like so much script which you find, this has zero error-trapping (a hobby-horse of mine, in case anyone hadn't noticed).

For example, there's no check to see if the file actually got deleted. In your case, you should add a check that makes sure the folder gets deleted. Once you're more proficient, you'll get into the habit of error-trapping EVERYTHING. Essentially, any program must assume that NOTHING will work, including creation of popular objects e.g FileSystemObject.
Answered 04/06/2011 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity