如何检查部分文件名并删除/替换ant中的文件?

如何从下载中检查部分文件名并从目标替换旧文件。
版本是文件名的一部分。如果旧版本文件不存在,则只需复制它。考虑“下载”中的文件是最新的。

文件夹“下载”具有来自服务器的最新文件。以及已经存在某些文件的“目标”文件夹。

文件名模式:<UNIQUE_NAME>_<VERSION>_<SOME-TYPE>.dat

/下载 - 所有都是最新的在这里

文件01_01.02.03_xy-z.dat
文件02_02.03.04_xy-z.dat
FILE_11_03.04.05_xy-z.dat

/目标 -
在文件02_01.00.02_xy-z.dat
文件04_01.00.00_xy-z.dat
FILE_03_01.00.01_xy-z.dat
FILE_11_01.01.00_xy-z之前.dat

/目标 - 移动后 (ToDo)
FILE01_01.02.03_xy-z.dat - 目标(简单复制)
中不存在 FILE02_02.03.04_xy-z.dat - 替换为最新的
FILE04_01.00.00_xy-z.dat - 无法下载最新(不执行任何操作)
FILE_03_01.00.01_xy-z.dat - 无法下载最新(不执行任何操作)
FILE_11_03.04.05_xy-z.dat - 替换为最新


白衣非少年
浏览 91回答 1
1回答

qq_花开花谢_0

为“for 循环”添加库<taskdef resource="net/sf/antcontrib/antlib.xml">&nbsp; &nbsp; <classpath>&nbsp; &nbsp; &nbsp; &nbsp; <pathelement location="lib/ant-contrib-1.0b3.jar" />&nbsp; &nbsp; </classpath></taskdef>通过迭代下载中的所有文件进行更新<target name="update" depends="download" description="moves downloded dat files to projects dest">&nbsp; &nbsp; <for param="file" delimiter=";">&nbsp; &nbsp; &nbsp; &nbsp; <path>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <fileset dir="${downloads}" includes="*.dat" casesensitive="false" />&nbsp; &nbsp; &nbsp; &nbsp; </path>&nbsp; &nbsp; &nbsp; &nbsp; <sequential>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>file: @{file}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <basename file="@{file}" property="filename" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <!--echo>filename: ${filename}</echo-->&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <propertyregex property="uniq" input="${filename}" regexp="^[^.]*(?=_)" select="\0" casesensitive="false" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>uniq: ${uniq}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <delete dir="${dest}" includes="${uniq}*" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <copy file="@{file}" tofile="${dest}/${filename}" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <var name="uniq" unset="true" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <var name="filename" unset="true" />&nbsp; &nbsp; &nbsp; &nbsp; </sequential>&nbsp; &nbsp; </for></target>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java