tags:

views:

112

answers:

2

I am trying to extract the directory and file name from a path. I have got it working with normal file names that only have a single dot as part of the extension name, but it fails to work if there are multiple dot's in the file name.

Normal case results in:

Web Content/javascript/more/andmore/evenmore AND uidoublerebel

I am wanting it to also handle a file name like:

ui.effects.core-1.7-doublerebel.js

results in:

Web Content/javascript/more/andmore/evenmore AND ui.effects.core-1.7-doublerebel

Can anyone help with the regular expression I have.

${content.dir.unix}/([^.])/([^.]).((css)|(js))$

<property name="content.dir.path" value="C:/ajm/zip/jdw-content"/>

<property name="file.name.problem" value="C:/ajm/zip/jdw-content/Web Content/javascript/ore/andmore/evenmore/ui.effects.core-1.7-doublerebel.js"/>

<property name="file.name.works" value="C:/ajm/zip/jdw-content/Web Content/javascript/more/andmore/evenmore/uidoublerebel.js"/>

<propertyregex override="yes"
  property="zip.dir.structure"  input="${file.name.problem}"
  regexp="${content.dir.unix}/([^\.]*)/([^\.]*)\.((css)|(js))$" replace="\1 AND \2"/>
<echo> messge = ${zip.dir.structure}</echo>

Thanks

Andy

A: 

I don't know ANT style regex, but I believe that if you replace [^.]* with just .*, your regex will succeeed. I.e. something like:

${content.dir.unix}/(.*)/(.*)\.((css)|(js))$

Br. Morten

Maate
A: 

Ant has got basename and dirname tasks that accomplish what you're looking for

<project name="demo" default="build">

    <property name="file.name.problem" value="Web Content/javascript/ore/andmore/evenmore/ui.effects.core-1.7-doublerebel.js"/

    <dirname property="file.dirname" file="${file.name.problem}"/>
    <basename property="file.basename" file="${file.name.problem}" suffix=".js"/>

    <target name="build">
        <echo>
        Original: ${file.name.problem}

        Dirname: ${file.dirname}
        Basename: ${file.basename}
        </echo>
    </target>

</project>
Mark O'Connor