Delete folders except one

2020-07-10 08:58发布

under the src folder I have the following folders: daos, business and model,I wanna delete using ant script, all the folders except "model" so I tried:

    <delete includeemptydirs="true">
    <fileset dir="${basedir}/src">
    <include name="**/*"/>
    <exclude name="model/*"/>
    </fileset>
   </delete>

All the folders are deleted excpet "model" which is empty !! all its files are deleted !

标签: ant
2条回答
太酷不给撩
2楼-- · 2020-07-10 09:51

Try instead

<delete includeemptydirs="true">
    <fileset dir="${basedir}/src">
        <include name="**/*"/>
        <exclude name="**/model/**"/>
    </fileset>
</delete>
查看更多
狗以群分
3楼-- · 2020-07-10 09:57

To the googlers of the future:

What worked for me:

<fileset dir="target">
    <include name="*/"/>
    <exclude name="big_and_complex_dir/"/>
</fileset>

This deleted everything (every files and directories) below target/, except target/big_and_complex_dir.

My intended goal was to avoid the unneeded directory walkthrough, which in case of the "big_and_complex_dir" took very long time.

It seems the fileset interpretation of ant has the non-trivial, non-intuitive behavior, that we need to close an include/exclude path with / if we intend to do recursive subdirectory operations as well.

查看更多
登录 后发表回答