Search, find and delete directories, subdirectories and files in batch?

Viewed 34

This is my directory structure:

K:.
|
+---PROGETTI PREMIERE
|   +---PROGETTO 1
|   |   \---AUTOSAVE
|   |
|   +---PROGETTO 2
|   |   \---AUTOSAVE
|   |
|   +---PROGETTO 3
|   |   \---AUTOSAVE
|   |
|   +---PROGETTO …
|   |   \---AUTOSAVE
|   |
|   \---PROGETTO N
|       \---AUTOSAVE
|

I would like to create a batch file capable of deleting the contents of the AUTOSAVE directories within each branch of PROGETTI PREMIERE.

Since I create projects on a constant basis, I can't add a new command line every time.

Which command should I use?

Furthermore, what command line is needed to be able to search, find and delete empty diirectories contained within my K: drive?

1 Answers

You can list subfolders with a for /d loop (just childs, no grandchilds) *)

for /d %%a in ("K:\PROGETTI PREMIERE\PROGETTO*") do ECHO del /y "%%a\AutoSave\*"

Remove the ECHO failsafe after verifying it does what you want.

For deleting empty folders, use the rd command (without switches it only deletes empty folders; just discard the "not empty" errormessage with 2>nul

*) or recursive with for /d /r

Related