You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Leif Hanack <le...@t-systems.com> on 2003/04/02 14:17:27 UTC
Problem with
Hello,
i have some problems with the dirname task. When calling the script below i
receive the following.
copyDate is a batch file that call my ant-script. The source dir is set to
the base dir of my script, but in this case i want to have a empty value for
source.dir. Is this possible?
Thanks in advance, Leif
c:\System\Utility>copyDate someDir
c:\System\Utility>ant -f
C:\System\Utility\antTasks\copy.xml -Dsource=someDir
Buildfile: C:\System\Utility\antTasks\copy.xml
init:
copy:
[echo] source : someDir
[echo] source dir : C:\System\Utility\antTasks
[echo] source name: someDir
[echo] target: C:\System\Utility\antTasks/20030402_0149_someDir
copy-FILE:
BUILD FAILED
file:C:/System/Utility/antTasks/copy.xml:42: Warning: Could not find file
C:\Sys
tem\Utility\antTasks\someDir to copy.
Here is the script:
<?xml version="1.0"?>
<project name="copy" basedir="." default="build">
<target name="init" description="initialize copy">
<!-- file or directory to copy -->
<property name="source" value=""/>
<tstamp>
<format property="date" pattern="yyyyMMdd_hhmm"/>
</tstamp>
</target>
<target name="copy" depends="init" if="source" description="">
<basename property="source.name" file="${source}" />
<dirname property="source.dir" file="${source}"/>
<echo message="source : ${source}" />
<echo message="source dir : ${source.dir}" />
<echo message="source name: ${source.name}" />
<!-- sets kind to DIR if source type is 'dir' -->
<available property="kind" type="dir" value="DIR" file="${source}"
/>
<!-- otherwise -->
<property name="kind" value="FILE" />
<property name="target" value="${source.dir}/${date}_${source.name}"
/>
<echo message="target: ${target}" />
<antcall target="copy-${kind}"/>
</target>
<target name="copy-DIR">
<copy todir="${target}">
<fileset dir="${source}"/>
</copy>
</target>
<target name="copy-FILE">
<copy file="${source}" tofile="${target}"/>
</target>
<target name="build" depends="init,copy" description="">
</target>
</project>