script

Hi everyone, happy new year, and whatever you wish yourself for the new year, I wish for you as well.
I would like a script that can run from a top level, and search all sub folders for a particular file name, if found, delete that file name.
example: run from top level folder and look for file name dadadada.xml if dadadada.xml is found, delete it. Thanks.
xzay1967Asked:
Who is Participating?
 
leakim971PluritechnicianCommented:
Hello xzay1967,

Try :


Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "C:\PATH\TO\FILE"
Set objFolder = objFSO.GetFolder(strFolder)

DeleteRecurs(objFolder)

Sub DeleteRecurs(objFolder)
	Set colFolders = objFolder.SubFolders
	For Each objSubFolder In colFolders
		Set colFiles = objSubFolder.Files
		For Each objFile in Colfiles
			If objFile.Name = "dadadada.xml" Then
				objFSO.DeleteFile objFile, true
			End If
		Next
		DeleteRecurs(objSubFolder)
	Next
End Sub

Open in new window

0
 
jazzIIIloveCommented:
Ok, but which scripting language and which platform Windows, Linux or Apple?

Best regards.
0
 
Bill PrewCommented:
This can be done with the DEL command.

del /s /q c:\toplevel\dadadada.xml

~bp
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
xzay1967Author Commented:
@jazz, batch or vb script would be fine. Thanks Leak, I will give your script a try.
0
 
xzay1967Author Commented:
I tried your script leak, no luck. Here are the changes I made to suit my need
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "U:\test"
Set objFolder = objFSO.GetFolder(strFolder)

DeleteRecurs(objFolder)

Sub DeleteRecurs(objFolder)
      Set colFolders = objFolder.SubFolders
      For Each objSubFolder In colFolders
            Set colFiles = objSubFolder.Files
            For Each objFile in Colfiles
                  If objFile.Name = "mymovies.xml" Then
                        objFSO.DeleteFile objFile, true
                  End If
            Next
            DeleteRecurs(objSubFolder)
      Next
End Sub
If I am reading this right, is supposed to delete the folders as well? I only want the script cycle thru the sub folders, and find mymovies.xml. and delete the mymovies.xml file, NOT the folders. Thanks again.
0
 
leakim971PluritechnicianCommented:
Check the case and permissions.
Tested and work great for me. It will not delete the folder(s).
0
 
xzay1967Author Commented:
You are right, it worked this time, thanks
0
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points! Happy New Year!
0
 
Bill PrewCommented:
Just curious, you indicated either a batch or VBS solution would be acceptable, but you didn't use my simple one line command approach, did it not do something you wanted?

~bp
0
 
xzay1967Author Commented:
My humble apologies bill, I did not even try your script until now. I really feel bad, and I don't fault you for feeling cheated. I don't know what I can do to make it up to you I hope my apologies give some form of solace.
0
 
Bill PrewCommented:
It's all good, just wanted to understand if I had missed something.  For me a one line built in command would have been what I would have used over a 15+ line bit of vbscript code, so wanted to see if I was missing something.

In the end as long as you have useful options and input to guide you that's all that matters.  Apology accepted, no problems.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.