How can I delete the contents of a folder from the command line on Windows?
I am writing a deployment script using MSBuild. I want to clear my web directories before copying all new files. My current target "Clean" looks like this:
<Target Name="Clean">
<Exec Command="del %(DeploymentSet.LocalWebRoot)\* /Q /F /S" IgnoreExitCode="true" />
</Target>
This takes a significant amount of time because each file is removed from each subfolder individually.
Is there a good way to delete everything from a given folder without deleting that folder? I want to keep my permissions and vdir installation information.
0
source to share
2 answers
You can rmdir /s /q
each subdirectory separately and then del %(DeploymentSet.LocalWebRoot)\* /Q /F
your net target. For example:
<Target Name="Clean">
<Exec Command="rmdir %(DeploymentSet.LocalWebRoot)\subdir1 /Q /S" IgnoreExitCode="true" />
<Exec Command="rmdir %(DeploymentSet.LocalWebRoot)\subdir2 /Q /S" IgnoreExitCode="true" />
...
<Exec Command="rmdir %(DeploymentSet.LocalWebRoot)\subdirN /Q /S" IgnoreExitCode="true" />
<Exec Command="del %(DeploymentSet.LocalWebRoot)\* /Q /F" IgnoreExitCode="true" />
</Target>
+1
source to share