In ant, how can i check if a set of files (comma-separated list of paths) exist or not?
For example I need to check if all paths listed in myprop
exist and if so i want to set a property pathExist
:
<property name="myprop" value="path1,path2,path3"/>
So in the example all of path1
path2
path3
must exist to set pathExist
to true
, otherwise false
.
I discovered that for a single resource I can use the resourceexist
task, but i can't figure out how to use that with a comma-separated list of paths.
How can I check the existence for a set of paths? Thanks!
You can use a combination of a
filelist
,restrict
andcondition
task for this.In the below example a filelist is created from the property with the comma-separated list of files. Using
restrict
a list of the files that don't exist is found. This is placed in a property which will be empty if all the files are found.You could use something like this to generate a failure message listing the missing files:
This can be solved with the set operations of Ant´s resource collections. If you calculate the intersection of the list of required files with the list of existing files it must not differ from the list of required files. This shows how to do it:
The
check
target reports the list of missing files only if a file is missing.Bundled conditions are the shortest solution to check for existence of multiple dirs or files :
To check for a commaseparated list of path use Ant addon Flaka , f.e. :
Another possibility is the use of scriptcondition task with a jvm scripting language like groovy,beanshell .. etc.