ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: Changing the "leading directory" path on a directory tree
Date Wed, 15 Mar 2006 16:34:21 GMT

Hi,

quick hack,  without handling of file endings, something like =

<!-- Import AntContrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml" />

<property name="path1" value="C:/dir_viewer/Since_Last_Change/abc/yada
yada/yada/Bob's Report.doc" />   
 <property name="path2" value="D:/Final_Files/Docs/abc/yada
yada/yada/Bob's Report.pdf" />    
    
<target name="main">
		
<propertyregex property="part2"
              input="${path1}"
              regexp="(.+/)(.+/.+/.+/.+)"
              select="\2"
/>

<echo>${part2}</echo>
     
 <propertyregex property="part1"
                input="${path2}"
                regexp="(.+/)(.+/.+/.+/.+)"
                select="\1"
/>   

<echo>${part1}</echo>
     
<script language="javascript">
    s=project.getProperty("part1")+project.getProperty("part2");
    project.setProperty("final", s);
</script>
         
<echo>${final}</echo>

Buildfile: C:\WKS\Eclipse\test\regexp.xml
main:
     [echo] abc/yada yada/yada/Bob's Report.doc
     [echo] D:/Final_Files/Docs/
     [echo] D:/Final_Files/Docs/abc/yada yada/yada/Bob's Report.doc 

 maybe you could wrap the logic into a macrodef

Regards, Gilbert

-----Original Message-----
From: Ninju Bohra [mailto:ninju_bohra@yahoo.com] 
Sent: Wednesday, March 15, 2006 3:26 PM
To: Ant Users List
Subject: Re: Changing the "leading directory" path on a directory tree

That is why I am using the override="true" in the <propertyregex> task
so that I can keep re-using the property named destfile
 
The real problem is that I don't know how to replace only the "leading"
directory path.  I want to change
 
file = C:/dir_viewer/Since_Last_Change/abc/yada yada/yada/Bob's
Report.doc
 
to 
 
destfile = D:/Final_Files/Docs/abc/yada yada/yada/Bob's Report.pdf
 
Note the "leading" directory path (C:/dir_viewer/Since_Last_Change) has
been replaced with the D:/Final_Files/Docs --- while the rest of the
path information stays the same (I can handle the changes of the
extension)
 
Any ideas?
 



----- Original Message ----
From: "Rebhan, Gilbert" <Gilbert.Rebhan@huk-coburg.de>
To: Ant Users List <user@ant.apache.org>; Ninju Bohra
<ninju_bohra@yahoo.com>
Sent: Wednesday, March 15, 2006 1:32:15 AM
Subject: RE: Changing the "leading directory" path on a directory tree


Hi,

when dealing with properties within a for loop, you
have to keep in mind, that properties are immutable,
so you have to use variable properties,
f.e. =

<target name="main">

<fileset id="files" dir="T:/foobar/blaa" includes="*.*" />

<for param="file">
<path>
<fileset refid="files" />
</path>
<sequential>
<echo>
     Filepath === @{file}
</echo>
<var name="filename" unset="true" />
<basename property="filename" file="@{file}" />

<echo>
Filename === ${filename}
</echo>
</sequential>
</for>

</target>

if you delete the line

<var name="filename" unset="true" />

the property ${filename} is set in the first loop
and stays the same in all following loops

Regards, Gilbert

-----Original Message-----
From: Ninju Bohra [mailto:ninju_bohra@yahoo.com] 
Sent: Tuesday, March 14, 2006 11:00 PM
To: Ant Users Group
Subject: Changing the "leading directory" path on a directory tree

Hello all,

I am not sure if I can explain this correctly, so I will show you the
target text and then explain the problem

   <target name="publish.documents" depends="init, fetch.files,
get.change.list">
   
      <property name="changes.dir"
value="C:\dir_viewer\Since_Last_changes"/>
      <property name="output.root.dir"
value="C:\dir_viewer\Documentation"/>
      <for param="file">
        <path>
          <fileset dir="${changes.dir}" excludes="${dont.convert}"/>
        </path>
        <sequential>
          <!-- construct the destination full filename and path, need to

               change the extension to .pdf and the replace the "leading
directory" path
               from ${changes.dir} to ${output.root.dir} -->
          <propertyregex override="yes"
            property="destfile"  input="@{file}"
            regexp=".*/([^\.]*)\.cpp" replace="\1"/>
          <!-- invoke the pdf convertor passing the two files paths -->
          <exec executable="C:\Program Files\e-PDF Document Converter
v2.1\doc2pdf.exe">
             <arg value="-i"/>
             <arg value="@{file}"/>
             <arg value="-o"/>
             <arg value="${destfile}"/>
          </exec>
          <!-- after converting the file we can delete the source file
-->
          <delete file="${file}"/>
        </sequential>
      </for>
      <!-- Now copy over all the remaining files from changes.dir -->
       <copy todir="${output.root.dir}">
          <fileset dir="${changes.dir}"/>
       </copy>
   </target>

I copied most of the <for> task text from the example provided in the
ant-contrib documentation and made my modifications.

The problem I am having is in the <propertyregex> task (the first task
afterthe <sequential>), what I want to do is convert filepaths that are
provided in the @{file} attribute from
  C:\dir_viewer\Since_Last_changes\abc\yada yada\yada\Bob.doc
    to
  ${output.root.dir}\abc\yada yada\yada\Bob.pdf

I know the code above will not accomplish all that (the <propertyregex>
is incorrect) but I did not know if it was even possible to do that with
property manipulations anyways.

Any ideas,

Thanx,

Ninju

---------------------------------------------------------------------
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