Solved

DOS Script -- delete .bak files in ALL subfolders ?

Posted on 2013-01-28
6
2,172 Views
Last Modified: 2013-01-29
I have multiple subfolders like c:\backup\test1\, c:\backup\test2\, etc.

What dos script will delete all .bak files in ALL subfolders ?

Example --> del c:\backup\*.*\*.bak
0
Comment
Question by:finance_teacher
  • 3
6 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 300 total points
ID: 38826611
This should do it

del c:\backup\*.bak /s

or you can start in the dir and work down under them (but if the directory does not exist it would carry on and delete *.bak from wherever you are at the moment...)

cd /d c:\backup
del *.bak /s

Steve

Steve
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 100 total points
ID: 38826613
Did you try

/S  Delete from all Subfolders (DELTREE)

del c:\backup\*.*\*.bak /s
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 300 total points
ID: 38826647
Dhaest - that syntax isn't valid due to the extra *.* for the directory level -- it must start from a "real" directory to scan down.  Just use as my post above.

Steve
0
 
LVL 1

Assisted Solution

by:ggoodwill
ggoodwill earned 100 total points
ID: 38826681
As Steve as said:

del c:\backup\*.bak /s

should work brilliantly.

I'd probably add /F and /Q extensions for good measure, to force delete of any that are read only and do it quietly without prompting to delete on global wildcard.
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 300 total points
ID: 38826696
/F potentially useful, or /A will do all files regardless of hidden/system/read only etc. too.
/Q shouldn't be needed with a *.BAK but doesn't hurt.

If you want to get fancy find the files individually:

for /r "c:\backup" %a in (*.bak) do del /a "%~a"
or from batch file:
for /r "c:\backup" %%a in (*.bak) do del /a "%%~a"

But /s and losing the *.* for directory is all that is needed.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now