如何删除给定路径中的所有文件和文件夹?
我尝试过此操作,但无法选择目录。
<Target Name="CleanSource" Condition="$(path)!=''">
<Message Text="path=$(path)"/>
<ItemGroup>
<fileToDelete Include="$(path)\**\*.*" />
<directoryToDelete Include="$(path)\**\" /><!these doest not select any directory at all-->
</ItemGroup>
<Message Text="file to delete:@(fileToDelete)"/>
<Message Text="directory to delete:@(directoryToDelete)"/>
<Delete Files="@(fileToDelete)" />
<Message Text="file effectively deleted:@(DeletedFiles)"/>
<RemoveDir Directories="@(directoryToDelete)" />
<Message Text="Directory effectively deleted:@(RemovedDirectories)"/>
</Target>
最佳答案
RemoveDir task删除指定的目录及其所有文件和子目录。您不必先删除文件和子目录。只需将目录名称传递给RemoveDir即可。
<ItemGroup>
<DirsToClean Include="work" />
</ItemGroup>
<Target Name="CleanWork">
<RemoveDir Directories="@(DirsToClean)" />
</Target>
关于msbuild - 如何使用msbuild删除所有文件和文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5080856/