Using ant, rename a directory without knowing the full path?

ぃ、小莉子 提交于 2019-12-05 02:28:54

This will only work as long as the dirset only returns 1 item.

<project name="Test rename" basedir=".">

  <target name="rename">
    <path id="package_name">
      <dirset dir=".">
        <include name="package-*"/>
      </dirset>
    </path>
    <property name="pkg-name" refid="package_name" />
    <echo message="renaming ${pkg-name} to package" />
    <move file="${pkg-name}" tofile="package" />
  </target>

</project>

If there are no subdirectories inside the package-3d28djh3 directory (or whatever it is called once you extracted it) you can use

<move todir="package" flatten="true" />
  <fileset dir=".">
    <include name="package-*/*"/>
  </fileset>
</move>

Otherwise, use the regexp mapper for the move task and get rid of the package-xxx directory:

<move todir="package">
  <fileset dir=".">
    <include name="package-*/*"/>
  </fileset>
  <mapper type="regexp" from="^package-.*/(.*)" to="\1"/>
</move>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!