简体   繁体   中英

ANT task to move and rename, files and folders, recursively

I have have a folder structure like so:

/PROJECT/PROJECT.html

/PROJECT/PROJECT_readme.txt

/PROJECT/PROJECT.css

/PROJECT/PROJECT.js

/PROJECT/abc_PROJECT_def.txt

/PROJECT/something.js

/PROJECT/other.txt

/PROJECT/somefolder/PROJECT_other.txt

I want to use ANT to copy the complete directory and also change the PROJECT string in the files or folder to a specified value eg mysuperproject, so the result folder structure is so :

/mysuperproject/mysuperproject.html

/mysuperproject/mysuperproject_readme.txt

/mysuperproject/mysuperproject.css

/mysuperproject/mysuperproject.js

/mysuperproject/abc_mysuperproject_def.txt

/mysuperproject/something.js

/mysuperproject/other.txt

/mysuperproject/somefolder/mysuperproject_other.txt

Is there a easy way to do that in ANT ?

The Move task should suit you. Read the linked docs carefully.

It's a core task, so you can use it without downloading of configuring anything.

I have a similar requirement. This is what I did:

  <target name="move-and-rename" description="Move and Rename">
        <copy todir="${toDir}" verbose="true" overwrite="true">
            <fileset dir="${fromDir}" includes="**" />
            <regexpmapper from="(.*)${fromName}(.*)" to="\1${toName}\2"/>
         </copy>             
  </target>

Invoke on command line as

ant move-and-rename -DfromName=project -DtoName=xxxproject -DfromDir=. -DtoDir=proj2

Hope it helps somebody else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM