本文介绍了如何使用msbuild删除所有文件和文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从给定路径删除所有文件和文件夹?
How can I delete all files and folders from a given path?
我尝试了这个,但是我无法选择目录.
I tried this, but I'm unable to select the directories.
<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>
推荐答案
最后,我确实使用powershell wich快得多:
Finally I did use powershell wich is much more fast:
<exec>
<executable>powershell.exe</executable>
<buildArgs><![CDATA[-command "& {if( [System.IO.Directory]::Exists($pwd) ){dir $pwd | ri -recurse
-force}}"]]></buildArgs>
</exec>
这篇关于如何使用msbuild删除所有文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!