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
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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