1
votes

Is it possible to input a text file which contains the list of files that needs to be deleted using Ant Delete task?

I know there is an option for giving a fileset inside the delete task but since I have 100's of files that need to be deleted using ant delete.

For example

<target name="removeJarsFromList">
    <delete includeEmptyDirs="true" failonerror="false">
        <fileset dir="${my_base_dir}">
          <include name="/a/file1.jar/**"/>
          <include name="/b/file2.jar/**"/>
          <include name="/somedir/file3.jar/**"/>
          <include name="/c/file4.jar/**"/>
        </fileset>
    </delete>
</target>

Instead is there an option to have the files that needs to be deleted in a text file and give the text file as input.

myDeleteFileList.txt will have contents something like this

/a/file1.jar
/b/file2.jar
/somedir/file3.jar
/c/file4.jar

And give this file as input to the fileset ?

1

1 Answers

1
votes

there's a includesfile attribute for the <delete> task.

includesfile: The name of a file. Each line of this file is taken to be an include pattern. All files are relative to the directory specified in dir. See HERE

<delete dir="${base.dir}" includesfile="abc.txt"/>

abc.txt:
(each line is an include pattern, relative to dir; avoid trailing / leading spaces)

**/fileA
/x/y/fileB
z/*.java

normally, the dir attribute in the <delete> task is used to delete the entire directory, but maybe this'll work. (i havent tried this, so) take a backup of your directory or try it on a temporary directory first!