how to write ant script to check a given string is a file or directory -
how use write ant script check file file or directory???
given string "c:\test\application\services\test"
i need know string
"c:\test\application\services\test"
is file or directory,
i use following script check, looks cannot decide s file or directory
<if> <available file="${sourcefile}" /> <then> <echo> file ${sourcefile}</echo> <copyfile src="${sourcefile}" dest="${targetfile}" /> <echo> single file copied: sourcefile = ${sourcefile}</echo> </then> <else> <if> <available file="${dir}" type="dir" /> <then> <echo> directory: ${sourcefile}</echo> <copy todir="${targetfile}"> <fileset dir="${sourcefile}" /> </copy> <echo> single dir copied: sourcefile = ${sourcefile}</echo> </then> </if> </else> </if>
how use ant it???
the if/else tasks not part of standard ant (requires 3rd party jar)
conditional execution of targets performed follows:
<project name="demo" default="process"> <property name="sourcefile" location="c:\test\application\services\test"/> <available property="sourcefile.is.a.file" file="${sourcefile}" type="file"/> <available property="sourcefile.is.a.dir" file="${sourcefile}" type="dir"/> <target name="process" depends="process-file,process-dir"/> <target name="process-dir" if="sourcefile.is.a.dir"> <echo message="${sourcefile} dir"/> </target> <target name="process-file" if="sourcefile.is.a.file"> <echo message="${sourcefile} file"/> </target> </project>
Comments
Post a Comment