【问题标题】:How to copy a file into directory without losing the previous contents of directory in ant?如何将文件复制到目录中而不会丢失ant中目录的先前内容?
【发布时间】:2012-05-24 12:49:47
【问题描述】:

您好,这是我将文件从一个位置复制到另一个位置的代码

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

虽然它正在完美地将文件复制到它的目的地,但你的问题是它正在删除以前的目录结构,如果我有的话

D:/a/b/c/d/ee 如果我现在已经有1,2,3,4 作为文件如果我想将另一个文件放入e,而不是将其放入e,上述任务首先删除D:/a/b/c/d/ee 中的所有文件并创建新路径为D:/a/b/c/d/e 并将新文件放在那里,所以我丢失了所有内容。无论如何,请帮助。尝试了一些东西,但它们没有用。

【问题讨论】:

    标签: ant


    【解决方案1】:

    你错了。 我创建了这个例子:

    <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/build.xml

    运行:
    [delete] 删除目录/tmp/t/a/b/c/d/e
    [mkdir] 创建的目录:/tmp/t/a/b/c/d/e
    [触摸] 创建 /tmp/t/a/b/c/d/e/1
    [触摸] 创建 /tmp/t/a/b/c/d/e/2
    [回显] 复制前:1;2
    [复制] 将 1 个文件复制到 /tmp/t/a/b/c/d/e
    [echo] 复制后:1;2;build.xml

    构建成功
    总时间:0秒

    【讨论】:

    • 嘿,是的,实际上我在目标目录中选择了不是所需的目录,因此它在新位置创建了一个新目录...现在我更改了它,它工作正常..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-10
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多