Windows 7 empty the entire directory from the command line

I run a batch file that expands the war file to a specific directory. However, I want to delete this directory before deploying it, recursively.

I found this script that should delete everything in the directory, including folders and files, but I get this error: "%% I was unexpected at that time."

FOR /D %%i IN ("C:/Program Files (x86)/Apache Software Foundation/Tomcat 6.0/abtapps/ROOT/*") DO RD /S /Q "%%i" DEL /Q "C:/Program Files (x86)/Apache Software Foundation/Tomcat 6.0/abtapps/ROOT/*.*" 

I just need an easy way to recursively delete my ROOT directory, either by installing the script above or using another method. Must be able to do this from a batch file.

I am running windows 7.

Decision

 rmdir ROOT /s /q mkdir ROOT 
+4
source share
3 answers

You must use rmdir / S. Check link

+9
source

I think what you are looking for is to clear the folder so as not to delete it and recreate it. This will actually clear the folder, so you don't need to recreate it.

 CD "C:/Program Files (x86)/Apache Software Foundation/Tomcat 6.0/abtapps/ROOT" && FOR /D %i IN ("*") DO RD /S /Q "%i" && DEL /Q *.* 

A few notes.
You use only one% when starting from the command line. doubles for batch files.
& & to run multiple commands on the same line.
* && are especially important in this case because you do not want del / q. to start if cd fails because you will delete the contents of the directory in which you started.

+4
source

Try the following:

forfiles / p "folder" / s / c "cmd / c rd / q @path

replace "folder" with your folder name or letter

example: forfiles / pf: / s / c "cmd / c rd / q @path

This will be repeated in all subfolders and will delete only empty folders. If you use it on the command line, you will receive error messages for non-empty folders. If you place the script package, it will take some time to run, depending on how many folders you have.

+2
source

All Articles