If you want to keep the root directory for some reason and really want to empty it, then you can do the following:
del /q caminho_destino\*
for /d %x in (caminho_destino\*) do @rd /s /q "%x"
The first command removes all files from the directory, and then the second recursively removes all nested directories, and keeps the root-level directory as is (except for its content that has been deleted). It is noteworthy that way_destination is the path of the directory you want to empty.
Note that inside a file . bat you need to fold the %
in the loop for
:
del /q caminho_destino\*
for /d %%x in (caminho_destino\*) do @rd /s /q "%%x"
Try
rd /s /q
– viana
@acklay tried but it erases the root too.
– Roknauta
If you put it like that:
rd /s /q C:\path\to\directory\*
will not?!– viana
@acklay does not give, it happens until an error message saying that is incorrect the label if you put the * .
– Roknauta
See my answer, I tested it here and it worked. You can also use the
Erase
.– Sidon
Take a look here for help: https://ss64.com/nt/del.html
– viana
Very Good! Delete sub-folders and files, but keep ROOT.
– Gabriel Antunes