1

I want to convert multiple file formats to a single file format. Example: D:\myrepo\rough has 3 files 1. abc.sql 2. def.xml 3. ghi.dmp

I want them all to be converted to .txt using glob mappers.

<?xml version ="1.0"?>
<project name = "roughone" default="taget1">
    <target name= "target1">
      <move todir="D:\myrepo\rough">
      <fileset dir="D:\myrepo\rough">
      </fileset>
      <mapper type ="glob" from="*" to="*.txt"/>
      </move>
    </target>
</project>

This is giving 1. abc.sql.txt 2. def.xml.txt 3. ghi.dmp.txt where as i need only abc.txt,def.txt and ghi.txt.

Plz let me know how this can be fixed(from= "." is not helping too).

user
  • 67
  • 1
  • 6

1 Answers1

0

Replace your globmapper with the following <regexpmapper>:

<regexpmapper from="^(.*)[.][^.]+$$" to="\1.txt"/>

The above regular expression captures the part of each file name before the final period. The regular expression also discards whatever extension the file previously had.

The double "$$" is needed because Ant would interpret a single "$" as the beginning of a property reference.

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28