English 中文(简体)
如何将文件复制到目录中而不在蚂蚁中丢失目录的上一个内容?
原标题:How to copy a file into directory without losing the previous contents of directory in ant?
  • 时间:2012-05-24 12:49:47
  •  标签:
  • ant

嗨,这是我从一个地方到另一个地方 复制一个文件的密码

<copy file="${MyParam}${files.Sloc}${files.names}" tofile="..${cmdname}${files.Tloc}${files.names}"> </copy>

虽然它正在完美地将文件复制到目的地, 但问题在于它正在删除上一个目录结构, 即如果我有的话

D:/a/b/c/d/e e 中的 ,如果我已经有 1,2,3,4 作为文件存在,如果我想将另一个文件放入 e ,而不是将其放入 e ,上述任务首先删除 D:/a/b/c/d/e 和所有文件 ,并创建新路径,如 D:/a/b/c/d/e/code > 和将新文件放在那里,这样我就会失去一切。

问题回答

You are wrong. I created this example:

<project default="run">
<target name="run">
    <!-- create new directory with some files -->
    <delete dir="a/b/c/d/e"/>
    <mkdir dir="a/b/c/d/e"/>
    <touch file="a/b/c/d/e/1"/>
    <touch file="a/b/c/d/e/2"/>

    <!-- list directory contents -->
    <fileset id="e.contents.before" dir="a/b/c/d/e"/>
    <property name="prop.e.contents.before" refid="e.contents.before"/>
    <echo>Before copy: ${prop.e.contents.before}</echo>

    <!-- copy some file to directory -->
    <copy file="build.xml" tofile="a/b/c/d/e/build.xml"> </copy>

    <!-- list directory contents -->
    <fileset id="e.contents.after" dir="a/b/c/d/e"/>
    <property name="prop.e.contents.after" refid="e.contents.after"/>
    <echo>After  copy: ${prop.e.contents.after}</echo>
</target>

输出在 Linux 上使用 Ant 1. 8.2 :

构建文件: / tmp/ t/ building. xml

run:
[delete] Deleting directory /tmp/t/a/b/c/d/e
[mkdir] Created dir: /tmp/t/a/b/c/d/e
[touch] Creating /tmp/t/a/b/c/d/e/1
[touch] Creating /tmp/t/a/b/c/d/e/2
[echo] Before copy: 1;2
[copy] Copying 1 file to /tmp/t/a/b/c/d/e
[echo] After copy: 1;2;build.xml

BUILD SUCCESSFUL
Total time: 0 seconds





相关问题
i want to continously run my java threads

I am running my java application where i have used threads... i am running this application using ant command on the terminal.. But when i close my terminal or press ctrl+c,then java program which was ...

Subant targets instead of ant

I m having a problem with subant and have no ideas any more. Can anyone help? Using Ant to replace some strings for other (i.e Productname and Version for "Foo" and "1.2") I used ...

java ant buildfile for project with dependencies

I am new to ant, but am trying to create an ant script that builds my current proeject with another project as a dependency. I have the ant script building my current project, but am unsure how to add ...

Building Apache Hive - impossible to resolve dependencies

I am trying out the Apache Hive as per http://wiki.apache.org/hadoop/Hive/GettingStarted and am getting this error from Ivy: Downloaded file size doesn t match expected Content Length for http://...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...