[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2013-01-28
6
Medium Priority
?
2,495 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 1200 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 400 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 1200 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 400 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 1200 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 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