Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Ant: Selecting files with fileset?

Tags:

build

ant

It's really easy to select a file with a specific filename, or filetype using fileset in ANT, however I have yet not figured out how to write a fileset that remove all files with a filename beginning with a dot, such as .builtpath, and .hgignore, but excluding .htaccess;

Here's my current file:

<delete includeemptydirs="true">

    <fileset dir="${temp.dir}/fromRepo">            
        <exclude name=".htaccess"/>
        <include name="**/*" /> <!-- How to select files starting with .?!-->
    </fileset>

</delete>
like image 823
Industrial Avatar asked Jan 25 '26 09:01

Industrial


1 Answers

Suggest you try:

<delete includeemptydirs="true">
    <fileset dir="${temp.dir}/fromRepo">            
        <exclude name="**/.htaccess"/>
    </fileset>
</delete>

If you don't specify any wildcard - as in ".htaccess" then that rule will only match the exact file name, i.e., '.htaccess' in the top-level directory of the fileset. Prepending the directory wildcard ** to .htaccess will tell Ant to exclude from the delete all files called '.htaccess' found under the directory hierarchy of the fileset.

There's an implicit include of all files if you don't specify any include rule - so no need to specify the 'global' include.

One thing to watch out for - setting includeemptydirs true will remove any empty directories when using a fileset with the delete task. A directory will only be considered empty if it doesn't contain any files. In other words: directories containing a file called '.htaccess' will not be deleted, but those with a '.htaccess' file will not be deleted - hope that's what you need.

like image 71
martin clayton Avatar answered Jan 28 '26 15:01

martin clayton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!