如何使用msbuild删除所有文件和文件夹 [英] How to delete all file and folders with msbuild

查看:952
本文介绍了如何使用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删除所有文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆