I want to rename my application folder with a time stamp and then unzip a newer version of my app using the same folder name. Using the Ant (move
task), it looks like you can move contents from one folder to another.
我想用时间戳重命名我的应用程序文件夹,然后使用相同的文件夹名称解压缩我的应用程序的较新版本。使用Ant(移动任务),看起来您可以将内容从一个文件夹移动到另一个文件夹。
Is this the only way I can do this in Ant?
这是我在Ant中做到这一点的唯一方法吗?
4 个解决方案
#1
The move task does do what you're after, but the naming is a bit confusing. If you consider your directory is a 'file' in the Java sense - a file being a filesystem handle that can represent, among others a directory or a file in the usual sense - then the move task makes sense.
移动任务确实做了你想要的事情,但命名有点令人困惑。如果您认为您的目录是Java意义上的“文件” - 文件是一个文件系统句柄,可以表示通常意义上的目录或文件 - 那么移动任务是有意义的。
So the following
所以以下
<move file="mySourceDirName" tofile="myTargetDirName"/>
means rename/move the directorymySourceDirName
to be instead myTargetDirName
.
表示将directorymySourceDirName重命名/移动为myTargetDirName。
The following then
接下来呢
<move file="mySourceDirName" todir="someExistingDir"/>
means to move the directory mySourceDirName
to become a child directory of the existing someExistingDir
directory.
意味着将目录mySourceDirName移动到现有someExistingDir目录的子目录。
So, in ant the 'file' attribute refers to the target in question, and the 'todir' attribute refers to the directory that is the new parent location for the target file or directory.
因此,在ant中,'file'属性引用所讨论的目标,'todir'属性引用作为目标文件或目录的新父位置的目录。
#2
Just spelling out the answer already given, which is correct...
只是拼出已经给出的答案,这是正确的......
<project default="move">
<tstamp/>
<target name="move">
<move file="foo" tofile="foo-${TSTAMP}"/>
</target>
</project>
This moves foo to foo-HHMM.
这将foo移动到foo-HHMM。
For example:
$ find .
.
./build.xml
./foo
./foo/bar.txt
$
$ ant
Buildfile: C:\tmp\ant\build.xml
move:
BUILD SUCCESSFUL
Total time: 0 seconds
$
$ find .
.
./build.xml
./foo-1145
./foo-1145/bar.txt
$
#3
If you want to rename folder, you can use move tag but it there is a cryptic way to use it. As @phasmal said you can use move but it moves the folder inside the desired folder. If you just want to rename, try following.
如果要重命名文件夹,可以使用移动标记,但有一种神秘的方式可以使用它。正如@phasmal所说,你可以使用move但它会将文件夹移动到所需文件夹中。如果您只想重命名,请尝试以下操作。
<move todir="newname">
<fileset dir="directory tobe renamed "/>
</move>
#4
I think the move task is what you want. Is there some reason you don't want to use it?
我认为移动任务就是你想要的。你有什么理由不想使用它吗?
It sounds like you're proposing moving the folder in which your build.xml file lives. Is that right? If so, I imagine ant might not be too happy it.
听起来你提议移动build.xml文件所在的文件夹。是对的吗?如果是这样,我想蚂蚁可能不会太高兴。
#1
The move task does do what you're after, but the naming is a bit confusing. If you consider your directory is a 'file' in the Java sense - a file being a filesystem handle that can represent, among others a directory or a file in the usual sense - then the move task makes sense.
移动任务确实做了你想要的事情,但命名有点令人困惑。如果您认为您的目录是Java意义上的“文件” - 文件是一个文件系统句柄,可以表示通常意义上的目录或文件 - 那么移动任务是有意义的。
So the following
所以以下
<move file="mySourceDirName" tofile="myTargetDirName"/>
means rename/move the directorymySourceDirName
to be instead myTargetDirName
.
表示将directorymySourceDirName重命名/移动为myTargetDirName。
The following then
接下来呢
<move file="mySourceDirName" todir="someExistingDir"/>
means to move the directory mySourceDirName
to become a child directory of the existing someExistingDir
directory.
意味着将目录mySourceDirName移动到现有someExistingDir目录的子目录。
So, in ant the 'file' attribute refers to the target in question, and the 'todir' attribute refers to the directory that is the new parent location for the target file or directory.
因此,在ant中,'file'属性引用所讨论的目标,'todir'属性引用作为目标文件或目录的新父位置的目录。
#2
Just spelling out the answer already given, which is correct...
只是拼出已经给出的答案,这是正确的......
<project default="move">
<tstamp/>
<target name="move">
<move file="foo" tofile="foo-${TSTAMP}"/>
</target>
</project>
This moves foo to foo-HHMM.
这将foo移动到foo-HHMM。
For example:
$ find .
.
./build.xml
./foo
./foo/bar.txt
$
$ ant
Buildfile: C:\tmp\ant\build.xml
move:
BUILD SUCCESSFUL
Total time: 0 seconds
$
$ find .
.
./build.xml
./foo-1145
./foo-1145/bar.txt
$
#3
If you want to rename folder, you can use move tag but it there is a cryptic way to use it. As @phasmal said you can use move but it moves the folder inside the desired folder. If you just want to rename, try following.
如果要重命名文件夹,可以使用移动标记,但有一种神秘的方式可以使用它。正如@phasmal所说,你可以使用move但它会将文件夹移动到所需文件夹中。如果您只想重命名,请尝试以下操作。
<move todir="newname">
<fileset dir="directory tobe renamed "/>
</move>
#4
I think the move task is what you want. Is there some reason you don't want to use it?
我认为移动任务就是你想要的。你有什么理由不想使用它吗?
It sounds like you're proposing moving the folder in which your build.xml file lives. Is that right? If so, I imagine ant might not be too happy it.
听起来你提议移动build.xml文件所在的文件夹。是对的吗?如果是这样,我想蚂蚁可能不会太高兴。