Solved

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

Posted on 2013-01-28
6
2,342 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

728 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