我有一个批处理文件,可以复制测试结果。它将创建目录,然后将结果复制到该目录。如果该目录已存在,它将创建一个新目录并将结果复制到新文件夹。以下是我的批处理文件的内容,它完成了我的需要。但是,我试图弄清楚如何更改初始目录名称。我的问题是,如何维护所有批次功能,但将初始文件夹称为“日期”而不是“date_run 1”。所以第一个目录是“date”,第二个是“date_run 2”,第三个是“date_run 3”(依此类推)。我知道这是一个棘手的问题,但我只是想知道如何实现这一目标。
@echo off
title Copy the Chrome results to the results folder
REM Code for creating a folder with today's date
set "a=%date:~10,4%-%date:~4,2%-%date:~7,2%_RUN "
set c=0
:loop
set /a c+=1
if EXIST "C:\SeleniumGrid\Results\%a%%c%\Basic_Survey\test_output\html\Chrome\" goto :loop
REM Create HTML directory and copy results
xcopy "C:\Automation Workspace\Survey\Basic_Survey\test-output\html\*.*" "C:\SeleniumGrid\Results\%a%%c%\Basic_Survey\test_output\html\Chrome\"
REM Create screenshot directory and copy results
xcopy "C:\Automation Workspace\Survey\Basic_Survey\test-output\Report_for_Basic_Survey_Chrome\screenshots\*.*" "C:\SeleniumGrid\Results\%a%%c%\Basic_Survey\test_output\screenshots\Chrome\"
答案 0 :(得分:1)
这是一个应该有效的调整:
set "a=%date:~10,4%-%date:~4,2%-%date:~7,2%"
set "c="
:loop
if "%c%"=="1" set "a=%a%_run "
if EXIST "C:\SeleniumGrid\Results\%a%%c%\Basic_Survey\test_output\html\Chrome\" set /a c+=1&goto loop
警告您的if exist
包含test
_ output
,但您显示的其余行包含test
- <!/ KBD> 的output
我建议您将C:\SeleniumGrid\Results
和Basic_Survey\test?output\html\Chrome
放入变量中,以便在必要时轻松更改