重命名与移动 Ant 任务 [英] Rename Vs Move Ant task

查看:39
本文介绍了重命名与移动 Ant 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我正在使用 cmd 来重命名一个文件夹,而不是 cmd.但在我的情况下,我将在这里移动 48746 个文件,所以大约需要 1 小时.请告诉我以最佳方式重命名该文件夹的适当方法.提前致谢.

Actually i am using <move> cmd for renaming one folder instead of <rename> cmd. but in my case i am moving here 48746 files, so takes 1 approx hour. pls tell me ant appropriate way to rename that folder in optimal way. Thanks in advance.

<target name="rename_folder_jet" depends="Upload_on_ftp">
    <move todir="${build.dir}_jet_${ver_number}">
        <fileset dir="${build.dir}">
            <include name="**/*.*"/>
        </fileset>
    </move>
</target>

推荐答案

尝试仅移动/重命名目录,而不是其所有内容.像这样:

Try to move/rename the directory only, rather than all its contents. Like this:

<target name="rename_folder_jet" depends="Upload_on_ftp">
    <move file="${build.dir}" todir="${build.dir}_jet_${ver_number}"/>
</target>

并且在开始之前确保目标目录不存在.

And make sure that the target directory does not exist before you start.

我试验了以下构建文件:

I experimented with the following build file:

<project default="rename_folder_jet">
  <property name="build.dir" value="build"/>
  <property name="ver_number" value="0.3"/>

  <target name="setup">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dir}/foo"/>
    <mkdir dir="${build.dir}/bar"/>
  </target>

  <target name="teardown">
    <delete dir="${build.dir}_jet_${ver_number}"/>
  </target>

  <target name="rename_folder_jet">
    <move file="${build.dir}" todir="${build.dir}_jet_${ver_number}"/>
  </target>
</project>

在调试中执行 Ant (ant -d) 很有趣.

Executing Ant in debug (ant -d) with the above is interesting.

案例 1:

ant teardown
ant setup
ant -d

在这种情况下,移动/重命名的目标目录不存在.Ant 的调试输出显示:

In this case, the target directory of the move/rename does not exist. The debug output of Ant shows:

 [move] Attempting to rename dir: C:\Users\sudocode\tmp\ant\build to C:\Users\sudocode\tmp\ant\build_jet_0.3\build

情况 2:

ant setup
ant
ant setup
ant -d

在这种情况下,目标目录在第二次执行时已经存在.Ant 的调试输出显示:

In this case, the target directory exists already on the second execution. The debug output of Ant shows:

     [move] Attempting to rename dir: C:\Users\sudocode\tmp\ant\build to C:\Users\sudocode\tmp\ant\build_jet_0.3\build
fileset: Setup scanner in dir C:\Users\sudocode\tmp\ant\build with patternSet{ includes: [] excludes: [] }
     [move] Deleting directory C:\Users\sudocode\tmp\ant\build\foo
     [move] Deleting directory C:\Users\sudocode\tmp\ant\build\bar
     [move] Deleting directory C:\Users\sudocode\tmp\ant\build

所以看起来如果目标目录不存在,Ant 会对该目录进行重命名.但是如果目标目录存在,它会复制到目录中,然后从源目录中删除.

So it seems that if the target directory does not already exist, Ant will do a rename of the directory. But if the target directory exists, it instead does a copy into the directory and delete from the source directory instead.

这篇关于重命名与移动 Ant 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆