Solved

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

Posted on 2013-01-28
6
2,294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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