Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 7 empty entire directory from command line

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
like image 683
UpHelix Avatar asked Dec 07 '22 21:12

UpHelix


2 Answers

You should use rmdir /S. Check out this link

like image 195
Grim Avatar answered Dec 24 '22 06:12

Grim


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.

like image 21
mkly Avatar answered Dec 24 '22 05:12

mkly