views:

488

answers:

1

I am writing a deployment script using MSBuild. I want to clean my web directories prior to copying all the new files in. My current "Clean" target looks like this:

 <Target Name="Clean">
    <Exec Command="del %(DeploymentSet.LocalWebRoot)\* /Q /F /S" IgnoreExitCode="true" />
  </Target>

This takes an considerable amount of time as each file is deleted from each subfolder individually.

Is there a nice way to remove everything from a given folder with out deleting that folder? I want to maintain my permissions and vdir setup info.

+1  A: 

You can rmdir /s /q each sub-directory individually, then del %(DeploymentSet.LocalWebRoot)\* /Q /F your clean 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>
Patrick Cuff
Trying to keep it generic so that clean can work for any given DeploymentSet.LocalWebRoot... will have to think about that one.
NotMyself
Yeah, there's a tradeoff there, and rmdir might not be significantly faster to warrant the trade.
Patrick Cuff