ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neil Benn <neil.b...@gmail.com>
Subject Re: ReplaceRegExp with windows filenames
Date Sat, 27 Aug 2005 18:01:02 GMT
Hello,

        Cracked it - I need to escape all the backslashes in the
replace twice, once for Java and once for the regex.  In addition, you
need to escape the backslashes in teh nat file for java and the regex
- that's a whol lot of backslashes:

  <target name="replace_inf_paths" depends="init">
    <loadfile srcFile="${basedir}/installer/CE/DropPaq.inf" 
	          property="inf_contents"/>
    
	<propertyregex property="basedir.escaped" input="${basedir}" regexp="\\"
		replace="\\\\\\\\\\\\\\\\" global="true"/>
	<propertyregex property="basedir.escaped2" input="${basedir.escaped}"
regexp="\:"
		replace="\\\\:" global="true"/>
    <propertyregex property="inf_contents.escaped" input="${inf_contents}" 
	               regexp="C\:\\.*\\DropPaq"
replace="${basedir.escaped2}" global="true"/>
    <echo message="----------------------------------------------------------"/>
	<echo message="${inf_contents}"/>
	<echo message="----------------------------------------------------------"/>
	<echo message="${inf_contents.escaped}"/>
	<echo message="${basedir.escaped2}"/>
  </target>

    In addition, you also need to escape the : bit.

    Right off to the pub now!  Thanks all for your help.

Cheers,

Neil

On 8/27/05, Neil Benn <neil.benn@gmail.com> wrote:
> Hello,
> 
>        Cheers for that - however that's not gonna work for me as I
> need to spit the data out into a text file which is used by another
> application to build a cab file for WindowsCE (different from a normal
> cab file).  This text file requires backslashes, forward slashes won't
> work.
>     I'm completly utterly stumped here - I need to have backslashes in
> a file and I cannot for the life of me work out what to do here!
> 
> Cheers,
> 
> Neil
> 
> On 8/26/05, Rebhan, Gilbert <Gilbert.Rebhan@huk-coburg.de> wrote:
> >
> > Hi,
> >
> > -----Original Message-----
> > From: Neil Benn [mailto:neil.benn@gmail.com]
> > Sent: Thursday, August 25, 2005 9:55 PM
> > To: Ant Users List
> > Subject: Re: ReplaceRegExp with windows filenames
> >
> > /*
> > [...]
> >
> >     So, it seems if I use ReplaceRegEx on the file or load the file
> > into a property and if I use one or two backslashes in the, I get out
> > something like this (either from an echo or in the file:
> >
> >      [echo] 1 = ,"DropPaqEtc",,"C:Documents and SettingsNeil BennMy
> > Documentssvn_timtrunkDropPaq\installer\CE"   ; The etc directory which
> > contains all image and the jar file
> >
> > [...]
> >
> > */
> >
> > Sorry, didn't get your problem right, but maybe a point in
> > the right direction :
> >
> > had a similar problem here with pathseparator ' \ ' on Windows =
> >
> > in one antscript i grab one filename/path out of a directory with
> > antcontrib/timestampselector and echo that property to a file :
> >
> > <path id="path.order">
> >             <fileset dir="${...}">
> >                 <include name="*.txt" />
> >             </fileset>
> >         </path>
> >         <timestampselector property="order.candidat"
> >                            pathref="path.order"
> >                            count="1"
> >                            age="eldest">
> >         </timestampselector>
> >
> >         <echo
> > file="C:/deployserver/path/to/mytxtfile/foobar.txt">${order.candidat}</e
> > cho>
> >
> > in another script i load the property ${order.candidat} again, but as
> > the path
> > in that property on windows is something like :
> >
> > C:\deployserver\path\to\mytxtfile\foobar.txt
> >
> > the property gets C:deployserverpathtomytxtfilefoobar.txt when loaded
> > cause the ' \ ' is not masked (has to be ' \\ ' in java)
> >
> > so i have to load it like that :
> >
> > <loadfile property="auftragtxt"
> > srcfile="C:/deployserver/path/to/mytxtfile/foobar.txt">
> > <filterchain>
> > <replacestring from="\" to="/" />
> > </filterchain>
> > </loadfile>
> >
> > and it get's loaded with ' / ' as pathseparator -> OK
> >
> > btw, i always use ' / ' instead of ' \ ' even on windows (ant handles
> > that for you),
> > because i noticed several strange things when using  ' \ ' on windows.
> >
> > i even created a patch for the ant faq.xml and the ant manual /
> > property.html
> > some time ago, but somehow no one noticed and it didn't get in.
> >
> > http://marc.theaimsgroup.com/?l=ant-user&m=110769112325881&w=2
> >
> > [ <faq id="win-backslashes"> ]
> >
> > Regards, Gilbert
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message