/build/static/layout/Breadcrumb_cap_w.png

Looking for some help with Vbscript

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

Answers (5)

Posted by: dchristian 13 years ago
Red Belt
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
Posted by: acidburn777 13 years ago
Yellow Belt
0
Thank you david

one question does the ParentFolder property return the parent folder of my script or file?
Posted by: dchristian 13 years ago
Red Belt
0
It'll be the parent folder of the file (objItem).
Posted by: acidburn777 13 years ago
Yellow Belt
0
objFSO.GetParentFolderName(objItem.Name) did the job for me.

Really Appreciate your help

Thank You so much
Posted by: anonymous_9363 13 years ago
Red Belt
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.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ