Script to delete a specific files in various subfolders

Hi guys,

I need a script, it could be powershell or a simple .bat file but I need to delete a config file in about 500-600 subfolders,

What is the easiest way, the name of the file and parent folder are fixed but the subfolder is variable, it could be like this "\private\1001\" and the next folder is "\private\1002\" and so on...

The file that needs to be deleted is names "config.reg"

is this possible?

thank you in advance
LVL 1
HakumAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
For copy and paste into a command prompt (in test mode, remove the uppercase ECHO to run it for real:
for /f "delims=" %a in ('dir /s /b "C:\Temp\config.reg"') do @(ECHO del "%a")

Open in new window

For a batch script, double up on the percent signs of the loop variable:
for /f "delims=" %%a in ('dir /s /b "C:\Temp\config.reg"') do @(ECHO del "%%a")

Open in new window

Powershell, in test mode as well; remove the -WhatIf argument from Remove-Item to run it for real:
Get-ChildItem "C:\Temp" -Filter "test.txt" -File -Recurse | Remove-Item -WhatIf

Open in new window

0
SnibborgOwnerCommented:
If these all sit in subfolders why not do a search in Explorer, highlight and delete?
0
Bill PrewCommented:
Should be able to do this with the DEL command, something like this will remove all matching files from all subfolders under the specified one.

del /s /q "C:\basedir\config.reg"

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What were the top attacks of Q1 2018?

The Threat Lab team analyzes data from WatchGuard’s Firebox Feed, internal and partner threat intelligence, and a research honeynet, to provide insightful analysis about the top threats on the Internet. Check out our Q1 2018 report for smart, practical security advice today!

HakumAuthor Commented:
Thanks guys.... you rock!!!!
0
Bill PrewCommented:
Just curious, any reason my solution (ID: 40733455) wasn't viable?  Seemed like the shortest, simplest solution that got the job done?

Or did I misunderstand the requirements?

~bp
0
HakumAuthor Commented:
Hi Bill, not at all! To be honest It was a glitch! Soo sorry, any of you know if its possible to edit and accept another solution?
0
Bill PrewCommented:
No worries.  I undid your original close of the question so that you can reclose as you see appropriate.

~bp
0
HakumAuthor Commented:
Thank you :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

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.