0

We have a batch file that we use to (robo)copy scripts to various computers on our network.

We need be able to write the result of the copy operation (success or fail) to an output file including the server name.

Here is where I am at in the process and don't know how to proceed.

@echo off

for /F "tokens=*" %%i in (Maquinas_log.txt) do (

  robocopy.exe "E:\HERRAMIENTAS\SCRIPTS\ActualizarFirmas" \\%%i\c$\temp firmas.exe /R:1 /W:1

)
exit
2
  • Not sure what you are asking. Please clarify your question. Commented Mar 8, 2023 at 19:09
  • Please don't close this. I think I get what OP is trying to do. Commented Mar 8, 2023 at 20:55

1 Answer 1

2

I think all you need to know about is ERRORLEVEL.

If you use call :label <params>, you can break up the logic in ways you aren't doing here. There are ways to do it without the call :label syntax but I prefer this method.

After running robocopy, you need to look at the ERRORLEVEL variable to determine success or not. You could ALSO simply check if the file is there after the robocopy line.

Something like this:

@echo off

Set SalidaArchivo=%TEMP%\RobocopyResults.txt

for /F "tokens=*" %%i in (Maquinas_log.txt) do call :RoboCopyFileWithResults "%%i"
goto :EOF

:: Note: goto :EOF arriba es "volver a la función de llamada".. en este caso saldrá
:: Note: goto :EOF above means "return to the calling function" which in this case will exit the batch.

:: ----------------------------------------------------------------
:RoboCopyFileWithResults
  Set ServidorNombre=%~1
  robocopy.exe "E:\HERRAMIENTAS\SCRIPTS\ActualizarFirmas" \\%%i\c$\temp firmas.exe /R:1 /W:1
  echo %ServidorNombre%=%ERRORLEVEL% >>%SalidaArchivo%
  goto :EOF

:: Note: goto :EOF arriba es "volver a la función de llamada"
:: Note: goto :EOF above means "return to the calling function"

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .