How to rename a folder using Ant?

后端 未结 4 2159
无人及你
无人及你 2021-02-19 18:58

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 mo

相关标签:
4条回答
  • 2021-02-19 19:29

    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.

    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
    $
    
    0 讨论(0)
  • 2021-02-19 19:34

    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.

    0 讨论(0)
  • 2021-02-19 19:36

    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.

    <move todir="newname">
       <fileset dir="directory tobe renamed "/>
    </move>
    
    0 讨论(0)
  • 2021-02-19 19:37

    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.

    So the following

    <move file="mySourceDirName" tofile="myTargetDirName"/>
    

    means rename/move the directorymySourceDirName to be instead 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.

    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.

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