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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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

If these all sit in subfolders why not do a search in Explorer, highlight and delete?
Bill PrewIT / Software Engineering ConsultantCommented:
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"


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
Virus Depot: Cyber Crime Becomes Big Business

The rising threat of malware-as-a-service is not one to be overlooked. Malware-as-a-service is growing and easily purchased from a full-service cyber-criminal store in a “Virus Depot” fashion. View our webinar recording to learn how to best defend against these attacks!

HakumAuthor Commented:
Thanks guys.... you rock!!!!
Bill PrewIT / Software Engineering ConsultantCommented:
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?

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?
Bill PrewIT / Software Engineering ConsultantCommented:
No worries.  I undid your original close of the question so that you can reclose as you see appropriate.

HakumAuthor Commented:
Thank you :)
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.