一、创建目录:
1 <?xml version="1.0"?> 2 <project default="test_mkdir"> 3 <target name="test_mkdir"> 4 <mkdir dir="test1/test2 est3"/> 5 </target> 6 </project>
运行结果:
①目录不存在时:
C:UsersxiongjiaweiDesktopingant_demo>ant
Buildfile: C:UsersxiongjiaweiDesktopingant_demouild.xml
test_mkdir:
[mkdir] Created dir: C:UsersxiongjiaweiDesktopingant_demo est1 est2
est3
BUILD SUCCESSFUL
Total time: 0 seconds
②目录存在时:
C:UsersxiongjiaweiDesktopingant_demo>ant
Buildfile: C:UsersxiongjiaweiDesktopingant_demouild.xml
test_mkdir:
BUILD SUCCESSFUL
Total time: 0 seconds
注:目录分隔符随便用/或,ANT都能自动识别。
二、删除目录
1 <?xml version="1.0"?> 2 <project default="delete_mkdir"> 3 <target name="delete_mkdir"> 4 <delete dir="test1"/> 5 </target> 6 </project>
运行结果:
C:UsersxiongjiaweiDesktopingant_demo>ant
Buildfile: C:UsersxiongjiaweiDesktopingant_demouild.xml
delete_mkdir:
[delete] Deleting directory C:UsersxiongjiaweiDesktopingant_demo est1
BUILD SUCCESSFUL
Total time: 0 seconds
注:删除操作可直接连目录下的子目录也一并删除而无提示。
三、复制、移动、重命名
1 <?xml version="1.0"?> 2 <project default="copy_mkdir"> 3 <target name="copy_mkdir"> 4 <!--复制--> 5 <copy file="src/Test.java" tofile="srcTESTTEST.txt"/> 6 <!--移动(重命名)--> 7 <move file="src副本.java" tofile="src/副本.txt"/> 8 </target> 9 </project>
运行结果:
C:UsersxiongjiaweiDesktopingant_demo>ant
Buildfile: C:UsersxiongjiaweiDesktopingant_demouild.xml
copy_mkdir:
[copy] Copying 1 file to C:UsersxiongjiaweiDesktopingant_demosrc
[move] Moving 1 file to C:UsersxiongjiaweiDesktopingant_demosrc
BUILD SUCCESSFUL
Total time: 0 seconds
C:UsersxiongjiaweiDesktopingant_demo>