我目前有一个批处理文件,可以将一些测试结果复制到目录中。该目录将有一个日期(yyyy-mm-dd)。如果该日期已存在,它将创建一个具有相同日期的新文件夹,但附加一个运行编号(yyyy-mm-dd run 2,yyyy-mm-dd run 3)
@echo off
title Copy the FF results to the results folder
set "date=%date:~10,4%-%date:~4,2%-%date:~7,2%"
set "run="
set "browser=FF"
set "results_paste=C:\TestProject\Results"
:loop
if "%run%"=="1" set "date=%date%_run "
if "%run%"=="1" set "run=2"
if EXIST "%results_paste%\%date%%run%\%browser%\" set /a run+=1&goto loop
REM Create HTML directory and copy results
xcopy "%workspace%\test-output\html\*.*" "%results_paste%\%date%%run%\%browser%\"
REM Create screenshot directory and copy results
xcopy "%workspace%\test-output\XML\screenshots\*.*" "%results_paste%\%date%%run%\XML\screenshots\"
如何使用ANT完成相同的功能?这是我到目前为止所拥有的。我不确定如何检查日期文件夹是否已存在,如果存在,则创建一个run 2文件夹。
<project default="CopyResults">
<property name="Run" value="" />
<tstamp>
<format property="Date" pattern="yyyy-mm-dd" locale="en,US,WIN" />
</tstamp>
<copy todir="C:/Results/${Date}${Run}/${Project}/${Browser}">
<fileset dir="C:/Program Files (x86)/Jenkins/jobs/${PROJECT_NAME}/workspace/test-output/html/*.*">
</copy>
<dirname property="directoryProperty" file="C:/Program Files (x86)/Jenkins/jobs/$PROJECT_NAME/workspace/test-output/${XML}/screenshots"/>
<mkdir dir="${directoryProperty}"/>
<copy todir="C:/Results/${Date}${Run}/${Project}/${XML}/screenshots/">
<fileset dir="C:/Program Files (x86)/Jenkins/jobs/${PROJECT_NAME}/workspace/test-output/${XML}/screenshots/*.*">
</copy>
答案 0 :(得分:1)
以下是示例的示例:
<project default="CopyResults">
<property name="target" location="c:/temp/anttests"/>
<property name="source" location="C:/temp/source"/>
<target name="CopyResults">
<tstamp>
<!-- uppercase M is month -->
<format property="Date" pattern="yyyy-MM-dd" locale="en,US,WIN" />
</tstamp>
<!-- calculate increment number -->
<resourcecount property="Run">
<dirset dir="${target}">
<include name="${Date}*"/>
</dirset>
</resourcecount>
<copy todir="${target}/${Date}${Run}/">
<fileset dir="${source}">
<include name="**/*"/>
</fileset>
</copy>
<!-- rest goes here -->
</target>
resourcecount任务是神奇的。在dirset中,选择具有日期和可选编号的所有目录。这是Run
的值希望这有帮助。