使用msbuild删除空目录 [英] Remove empty directories using msbuild

查看:88
本文介绍了使用msbuild删除空目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何递归处理路径,以便处理完成后,路径下没有空目录.

How can I process a path recursively so that once the processing completes there are no empty directories under the path.

例如,假设我们有C:\Dir1\Dir2\Dir3,并且这些目录中都没有文件.结果应该是删除所有三个目录.

For example, say we have C:\Dir1\Dir2\Dir3 and there are no files in any of these directories. The outcome should be the removal of all three directories.

我想在不使用自定义任务的情况下完成此任务.

I would like to accomplish this without the use of custom tasks.

推荐答案

类似的方法应该可以工作,尽管只是为了获取数组长度,也没有检查数以千计的文件的性能.

Something like this should work, didn't check the performance of counting thousands of files though just to get array length...

<Project DefaultTargets="Foo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="Foo">
        <ItemGroup>
            <Directories Include="$([System.IO.Directory]::GetDirectories('D:\foo', '*', System.IO.SearchOption.AllDirectories))" />
            <Directories>
                <Files>$([System.IO.Directory]::GetFiles("%(Directories.Identity)", "*", System.IO.SearchOption.AllDirectories).get_Length())</Files>
            </Directories>
        </ItemGroup>        
        <RemoveDir Directories="@(Directories)" Condition="%(Files)=='0'" />
    </Target>
</Project>

这篇关于使用msbuild删除空目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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