使用ant,在不知道完整路径的情况下重命名目录?

发布于 2024-08-28 09:13:24 字数 1117 浏览 6 评论 0原文

给定一个包含未知目录的 zip 文件,如何重命名该目录或将该目录移动到规范化路径?

<!-- Going to fetch some stuff -->
<target name="get.remote">

    <!-- Get the zipfile -->
    <get src="http://myhost.com/package.zip"
         dest="package.zip"/>

    <!-- Unzip the file -->
    <unzip src="package.zip"
           dest="./"/>

    <!-- Now there is a package-3d28djh3 directory.  The part after package- is
         a hash and cannot be known ahead of time -->

    <!-- Remove the zipfile -->
    <delete file="package.zip"/>

    <!-- Now we need to rename "package-3d28djh3" to "package".  My best attempt
         is below, but it just moves package-3d28djh3 into package instead of
         renaming the directory. -->

    <!-- Make a new home for the contents. -->
    <mkdir dir="package" />

    <!-- Move the contents -->
    <move todir="package/">
      <fileset dir=".">
        <include name="package-*/*"/>
      </fileset>
    </move>

</target>

我不是蚂蚁用户,任何见解都会有所帮助。

非常感谢,-马特

Given a zipfile with an unknown directory, how can I rename or move that directory to a normalized path?

<!-- Going to fetch some stuff -->
<target name="get.remote">

    <!-- Get the zipfile -->
    <get src="http://myhost.com/package.zip"
         dest="package.zip"/>

    <!-- Unzip the file -->
    <unzip src="package.zip"
           dest="./"/>

    <!-- Now there is a package-3d28djh3 directory.  The part after package- is
         a hash and cannot be known ahead of time -->

    <!-- Remove the zipfile -->
    <delete file="package.zip"/>

    <!-- Now we need to rename "package-3d28djh3" to "package".  My best attempt
         is below, but it just moves package-3d28djh3 into package instead of
         renaming the directory. -->

    <!-- Make a new home for the contents. -->
    <mkdir dir="package" />

    <!-- Move the contents -->
    <move todir="package/">
      <fileset dir=".">
        <include name="package-*/*"/>
      </fileset>
    </move>

</target>

I'm not much of an ant user, any insight would be helpful.

Thanks much, -Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酷炫老祖宗 2024-09-04 09:13:24

仅当 dirset 仅返回 1 项时,此方法才有效。

<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>

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>
夜未央樱花落 2024-09-04 09:13:24

如果 package-3d28djh3 目录(或解压后调用的任何名称)内没有子目录,则可以使用

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

否则,使用 regexp 映射器进行移动任务并删除 package-xxx 目录:

<move todir="package">
  <fileset dir=".">
    <include name="package-*/*"/>
  </fileset>
  <mapper type="regexp" from="^package-.*/(.*)" to="\1"/>
</move>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文