|
View:
New views
12 Messages
—
Rating Filter:
Alert me
|
|
|
Alternative for <available> taks to check a pattern of file existenceHi,
I need to check for existence of files with some extension say *.txt in a folder and if present execute a target.. I found only <available> task which checks for the existence of single file only when the name of the file known. I wanted to check whether *.txt is present or not.. if present execute a target.. Can anyone please help me.. Thanks in advance. |
|
|
Re: Alternative for <available> taks to check a pattern of file existenceOn Thu, Oct 29, 2009 at 12:00, cvsusr <spers@...> wrote:
> > Hi, > > I need to check for existence of files with some extension say *.txt in a > folder and if present execute a target.. > > I found only <available> task which checks for the existence of single file > only when the name of the file known. I wanted to check whether *.txt is > present or not.. if present execute a target.. > > Can anyone please help me.. > > Thanks in advance. > One option would be to use an appropriate <fileset> and loop over it with <for>, but <for> requires ant-contrib. -- Francis Galiegue ONE2TEAM Ingénieur système Mob : +33 (0) 683 877 875 Tel : +33 (0) 178 945 552 fge@... 40 avenue Raymond Poincaré 75116 Paris --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Alternative for <available> taks to check a pattern of file existenceHi,
Thanks for your reply.. I know to use Fileset.. but how to check with forloop.. if possible, Can you please give me an example? Im new to this concept and hence requesting your help.. Thanks
|
|
|
Re: Alternative for <available> taks to check a pattern of file existenceI tried this.. this is printing the *.txt file that exist in the current folder
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <for param="file"> <path> <fileset dir="." includes="*.txt"/> </path> <sequential> <echo> file list::: @{file} </echo> </sequential> </for> Now i need to check if the file exist then perform the target.. Do i need to use condition for this?? Thanks Sri
|
|
|
RE: Alternative for <available> taks to check a pattern of file existence-----Original Message----- From: cvsusr [mailto:spers@...] Sent: Thursday, October 29, 2009 12:00 PM To: user@... Subject: Alternative for <available> taks to check a pattern of file existence /* Hi, I need to check for existence of files with some extension say *.txt in a folder and if present execute a target.. I found only <available> task which checks for the existence of single file only when the name of the file known. I wanted to check whether *.txt is present or not.. if present execute a target.. */ one possible solution, the extension you're are looking for is part of the glob attribute = your/path/**/*.yourextension means recursive your/path/*.yourextension means non recursive examplescript, look for files with .xml extension in C:/Temp and set property with number of found files the condition checks whether there are *.xml files in C:/Temp - means property set by scriptdef != 0 and then your targets use if / unless with condition property <project name="bla" default="main" basedir="."> <scriptdef name="filecount" language="ruby"> <attribute name="glob"/> <attribute name="property"/> $project.setProperty "#{$attributes.get('property')}", Dir.glob("#{$attributes.get('glob')}").length.to_s </scriptdef> <target name="checkfiles"> <filecount glob="C:/Temp/**/*.xml" property="xmlfiles"/> <condition property="files"> <not> <equals arg1="${xmlfiles}" arg2="0" /> </not> </condition> </target> <target name="foo" if="files"> <echo>${xmlfiles} files found ..</echo> </target> <target name="foobar" unless="files"> <echo>no files found ..</echo> </target> <target name="main" depends="checkfiles,foo,foobar"/> </project> Regards, Gilbert --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
RE: Alternative for <available> taks to check a pattern of file existenceP.S. : you may also check for existence of specific files via fileset if that is enough for your purpose = <fileset dir="your/path" includes="**/*.txt" id="checkdir"/> <condition property="nofiles"> <equals arg1="${toString:checkdir}" arg2="" /> </condition> and then f.e. = <fail if="nofiles" message="No TxtFiles around !!" /> or <target name="foo" if="nofiles"> .. or <target name="foo" unless="nofiles"> Regards, Gilbert -----Original Message----- From: cvsusr [mailto:spers@...] Sent: Thursday, October 29, 2009 12:00 PM To: user@... Subject: Alternative for <available> taks to check a pattern of file existence /* Hi, I need to check for existence of files with some extension say *.txt in a folder and if present execute a target.. I found only <available> task which checks for the existence of single file only when the name of the file known. I wanted to check whether *.txt is present or not.. if present execute a target.. */ one possible solution, the extension you're are looking for is part of the glob attribute = your/path/**/*.yourextension means recursive your/path/*.yourextension means non recursive examplescript, look for files with .xml extension in C:/Temp and set property with number of found files the condition checks whether there are *.xml files in C:/Temp - means property set by scriptdef != 0 and then your targets use if / unless with condition property <project name="bla" default="main" basedir="."> <scriptdef name="filecount" language="ruby"> <attribute name="glob"/> <attribute name="property"/> $project.setProperty "#{$attributes.get('property')}", Dir.glob("#{$attributes.get('glob')}").length.to_s </scriptdef> <target name="checkfiles"> <filecount glob="C:/Temp/**/*.xml" property="xmlfiles"/> <condition property="files"> <not> <equals arg1="${xmlfiles}" arg2="0" /> </not> </condition> </target> <target name="foo" if="files"> <echo>${xmlfiles} files found ..</echo> </target> <target name="foobar" unless="files"> <echo>no files found ..</echo> </target> <target name="main" depends="checkfiles,foo,foobar"/> </project> Regards, Gilbert --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Alternative for <available> taks to check a pattern of file existenceOn Thu, Oct 29, 2009 at 13:00, cvsusr <spers@...> wrote:
> > I tried this.. this is printing the *.txt file that exist in the current > folder > <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> > <for param="file"> > <path> > <fileset dir="." includes="*.txt"/> > </path> > <sequential> > <echo> file list::: @{file} </echo> > </sequential> > </for> > > > Now i need to check if the file exist then perform the target.. Do i need > to use condition for this?? > Well, no, since if there's no file, there will be no iteration at all... Hence my suggestion. A fileset can be empty. -- Francis Galiegue ONE2TEAM Ingénieur système Mob : +33 (0) 683 877 875 Tel : +33 (0) 178 945 552 fge@... 40 avenue Raymond Poincaré 75116 Paris --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Alternative for <available> taks to check a pattern of file existenceHi Francis Galiegue & Gilbert ,
Thanks a lot for replying. I got it done taking inputs from all your comments. Below is the code that is working fine. <target name="check-abc"> <for param="file"> <path> <fileset id="file.exist" dir="." includes="*.txt"/> </path> <sequential> <echo> file list::: @{file} </echo> <available file="@{file}" property="abc.present"/> </sequential> </for> </target> <target name="do-if-abc" depends="check-abc" if="abc.present"> <echo> true</echo> </target> Thanks a lot again for helping. Regards Sri
|
|
|
RE: Alternative for <available> taks to check a pattern of file existence-----Original Message----- From: cvsusr [mailto:spers@...] Sent: Thursday, October 29, 2009 3:34 PM To: user@... Subject: Re: Alternative for <available> taks to check a pattern of file existence /* <target name="check-abc"> <for param="file"> <path> <fileset id="file.exist" dir="." includes="*.txt"/> </path> <sequential> <echo> file list::: @{file} </echo> <available file="@{file}" property="abc.present"/> </sequential> </for> </target> */ using for - which requires antcontrib also - when all you want to know is whether there are any files with a specific extension or name is redundant; all you need is a fileset and a condition <fileset dir="your/path" includes="**/*.txt" id="checkdir"/> <target name="check-abc"> <condition property="abc-present"> <not> <equals arg1="${toString:checkdir}" arg2="" /> </not> </condition> </target> <target name="do-if-abc" depends="check-abc" if="abc.present"> <echo> true</echo> </target> Regards, Gilbert --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
RE: Alternative for <available> taks to check a pattern of file existenceHi Gilbert,
Thanks.. I replace the code with this.. its working fine.. Thanks for correcting me.. Regards Sri
|
|
|
Re: Alternative for <available> taks to check a pattern of file existenceOkay, the idea of using a fileset to specify possible matches by pattern is right. All you have to add to that is the use of the resourcecount task/condition to count the number of files matched. If you're using a version of Ant earlier than 1.7.0 you can use <pathconvert setonempty="false"> with an <isset> condition to determine a fileset's emptiness.
-Matt --- On Thu, 10/29/09, cvsusr <spers@...> wrote: > From: cvsusr <spers@...> > Subject: Alternative for <available> taks to check a pattern of file existence > To: user@... > Date: Thursday, October 29, 2009, 6:00 AM > > Hi, > > I need to check for existence of files with some extension > say *.txt in a > folder and if present execute a target.. > > I found only <available> task which checks for the > existence of single file > only when the name of the file known. I wanted to check > whether *.txt is > present or not.. if present execute a target.. > > Can anyone please help me.. > > Thanks in advance. > > > > > -- > View this message in context: http://www.nabble.com/Alternative-for-%3Cavailable%3E-taks-to-check-a-pattern-of-file-existence-tp26110901p26110901.html > Sent from the Ant - Users mailing list archive at > Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Alternative for <available> taks to check a pattern of file existenceOn 2009-10-29, cvsusr <spers@...> wrote:
> I need to check for existence of files with some extension say *.txt in a > folder and if present execute a target.. Use the condition task with a resourcecount condition to ste a property and make your target use that property. Stefan --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
| Free embeddable forum powered by Nabble | Forum Help |