Question

I have a batch file that will copy test results. It will create the directory, and then copy results to that directory. If the directory already exists, it will create a new one and copy the results to the new folder. Below are the contents of my batch file, and it accomplishes what I need. However, I am trying to figure out how to change the initial directory name. My question is, how can I maintain all the batches functionality, but have the initial folder be called "date" instead of "date_run 1". So the first directory will be "date", the second "date_run 2", and the third "date_run 3" (and so on). I know its a ticky tack thing, but I'm just curios on how to accomplish this.

@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\"
Was it helpful?

Solution

Here's an adjustment that should work:

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

caution your if exist contains test_output but the remaining lines you show contain test-output!

I'd suggest you put C:\SeleniumGrid\Results and Basic_Survey\test?output\html\Chrome into variables so that they can be changed easily as necessary

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top