Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

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.
0
xzay1967
Asked:
xzay1967
  • 4
  • 3
  • 3
  • +1
1 Solution
 
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now