Rename Vs Move Ant task

前端 未结 1 1570
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 16:32

Actually i am using cmd for renaming one folder instead of cmd. but in my case i am moving here 48746 files, so takes 1

相关标签:
1条回答
  • 2021-01-15 17:00

    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>
    

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

    Case 1:

    ant teardown
    ant setup
    ant -d
    

    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
    

    Case 2:

    ant setup
    ant
    ant setup
    ant -d
    

    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
    

    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.

    0 讨论(0)
提交回复
热议问题