[英]Using ant, rename a directory without knowing the full path?
給定具有未知目錄的zipfile,如何將該目錄重命名或移動到規范化路徑?
<!-- 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>
我不是一個螞蟻用戶,任何見解都會有所幫助。
非常感謝,-Matt
只有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>
如果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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.