I am running a batch file which deploys a war file to a specific directory. However, I want to empty that directory before deploying to it, recursively.
I found this script that is supposed to remove everything in the directory including folders and files but I get this error: "%%i was unexpected at this 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 a simple way to recursively empty my ROOT directory either by fixing the script above or with another method. Have to be able to do this from a batch file.
I am running windows 7.
SOLUTION
rmdir ROOT /s /q
mkdir ROOT
You should use rmdir /S. Check out this link
I think what you are looking for is to clear the folder not to delete it and recreate it. This will actualy clear the folder so you don't have 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 only use a single % when running from the command line. doubles are for batch files.
&& is for running multiple commands on the same line.
* The &&'s are especially important in this case because you do not want the del /q . to run if the cd fails as you will delete to contents of what ever directory you started in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With