1

I have the next script, and I need it to save all the xcopy files copy outputs to one log file,

:tmdeploy
title Deploying Edithor - %deployer%
set src_folder=S:\ApliTelinver\Compilacion\Edithor 10.5\CompilacionQA
set dst_folder=S:\ApliTelinver\Ambientes-Edithor\Sincronizacion\Test\Test-Mantenimiento
set filelist=filelist-tm.txt
echo Origen: %src_folder%
echo Destino: %dst_folder%
echo.
REM for /f %%i in (%filelist%) DO xcopy /S/E/U/Y "%src_folder%\%%i" "%dst_folder%" > "%dd%.log"
for /f "delims=" %%i in (%filelist%) do (
    xcopy /S/E/U/Y "%src_folder%\%%i" "%dst_folder%" > "%dd%.log"
)
echo.
pause
goto end

The problem is that I only get the last file copy in the output. And how to properly do a timestamp for .log file?

Thank you

BoDiE2003
  • 1,349
  • 6
  • 28
  • 41

1 Answers1

4

You should use the appended redirection operator, >> instead of >.

So, your for loop will look like this:

REM for /f %%i in (%filelist%) DO xcopy /S/E/U/Y "%src_folder%\%%i" "%dst_folder%" >> "%dd%.log"
for /f "delims=" %%i in (%filelist%) do (
    xcopy /S/E/U/Y "%src_folder%\%%i" "%dst_folder%" >> "%dd%.log"
)
adarshr
  • 61,315
  • 23
  • 138
  • 167
  • Thank you, and which is the proper timestamp way to do it, so my log file will have the right timestamp. – BoDiE2003 Jun 08 '11 at 16:46
  • What do you mean? And where is `%dd%` set? – adarshr Jun 08 '11 at 16:48
  • Does [this](http://stackoverflow.com/questions/6244963/how-to-output-date-to-a-text-file-filename-in-windows-xp/6245000#6245000) help? – adarshr Jun 08 '11 at 16:49
  • It does, helps a lot, thanks, but its not doing minutes output. – BoDiE2003 Jun 08 '11 at 16:57
  • It's doing for me. I just got `my-file-08-06-2011_18-12-06.txt` – adarshr Jun 08 '11 at 17:12
  • Strange I got: 08-06-2011_13.log – BoDiE2003 Jun 08 '11 at 17:27
  • @BoDiE2003: From the fact that @adarshr gets the correct name and you don't I presume that you are obtaining `dd` based on the current date & time and and the issue is related to how the date/time output is formatted. Seems like the formula does not apply well in your case because the date/time string is formatted differently from how it is expected by the formula. So, seconding @adarshr's request here, please show us the definition of `dd`. – Andriy M Jun 09 '11 at 05:19
  • This is what Im using right now for example to do a `for` loop and save the output to a log file: `xcopy /S/E/U/Y "%src_folder%\%%i" "%dst_folder%" >> "logs\t3-!today!_!now!.log"` And I'm using the definition of `!today!_!now!` as @adarshr is explaining in his post: `setlocal ENABLEDELAYEDEXPANSION set today=!date:/=-! set now=!time::=-! set millis=!now:*.=! set now=!now:.%millis%=! ` – BoDiE2003 Jun 09 '11 at 12:51
  • What are the outputs of `date /t` and `time /t` on your machine? – adarshr Jun 09 '11 at 14:14
  • And those of `echo %date%` and `echo %time%` also please. – adarshr Jun 09 '11 at 14:21