2014-05-01 51 views
0

我有一个将复制测试结果的批处理文件。它将创建该目录,然后将结果复制到该目录。如果该目录已经存在,它将创建一个新目录并将结果复制到新文件夹。以下是我的批处理文件的内容,它完成了我所需要的内容。但是,我试图找出如何更改初始目录名称。我的问题是,如何维护所有批处理功能,但将初始文件夹称为“日期”而不是“date_run 1”。因此,第一个目录将是“日期”,第二个“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

如果您指定的批处理文件解释和操作系统这将是有益的。看着文件路径,我猜测Windows和cmd.com的版本。请修改您的问题以添加此信息,而不是添加评论。 –

回答

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-output

我建议你把C:\SeleniumGrid\ResultsBasic_Survey\test?output\html\Chrome到变量,使他们可以很容易地根据需要改变

相关问题