批处理:for / f + xcopy输出 - 保存到.log

时间:2011-06-08 16:40:47

标签: scripting batch-file scripting-language

我有下一个脚本,我需要它将所有xcopy文件复制输出保存到一个日志文件中,

: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

问题是我只在输出中获得最后一个文件副本。以及如何正确地为.log文件做时间戳?

谢谢

1 个答案:

答案 0 :(得分:4)

您应该使用附加的重定向运算符>>而不是>

因此,您的for循环将如下所示:

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"
)