Search code examples
shellant

Is there an easy way to zero the contents of a file using Apache Ant?


I have an Ant build file that deletes a number of unwanted CSS files from the DITA Open Toolkit. My customers are complaining that the missing CSS are throwing 404s. So instead of deleting the files, I'd like to zero out their content. With the shell, I can just :>| $file. I'd like to do the same/similar from Ant.

Also I don't know in advance where those CSS files are and use name="**/file.css" to delete them.


Solution

  • This seems to work:

    <replaceregexp match=".*" replace="" flags="s" >
      <fileset dir="." includes="**/file.css" />
    </replaceregexp>
    

    It basically says "replace everything in each file with nothing". It might not meet your "Easy Way" criterion. It certainly isn't pretty, and would merit an explanatory comment in a buildfile.

    You might also consider putting a comment in the file instead of leaving it completely empty.