嗨,这是我将文件从一个位置复制到另一个位置的代码
<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
中的e
以及D:/a/b/c/d/e
中的所有文件,并将新路径设置为{{1}}并将新文件放在那里,这样我就失去了一切。无论如何,请帮忙。尝试了一些东西,但他们没有工作。
答案 0 :(得分:0)
你错了。 我创建了这个例子:
<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:
Buildfile:/tmp/t/build.xml
运行:
[删除]删除目录/ tmp / t / a / b / c / d / e
[mkdir]创建目录:/ tmp / t / a / b / c / d / e
[touch]创建/ tmp / t / a / b / c / d / e / 1
[touch]创建/ tmp / t / a / b / c / d / e / 2
[echo]复制前:1; 2
[复制]将1个文件复制到/ tmp / t / a / b / c / d / e
[echo]复制后:1; 2; build.xml
建立成功的作用 总时间:0秒