我有一个COPY批处理文件,可以将文件复制到多台计算机(大约300个,正在从单独的文本文件中读取),我希望看到文件副本的结果。如果我能看到成功和失败的文件副本,那就太棒了。但如果只能看到失败的副本,那就没关系了。
这是我现在拥有的代码,它运行良好。这些文件正被复制到我设置的测试计算机上。提前谢谢大家花时间帮我解决这个问题。
for /f "Tokens=*" %%a in (c:\computers.txt) do (set MyVar=%%a& call :next)
pause
goto EOF
:next
echo %MyVar%
if exist "\\%MyVar%\C$\Users\Public\Desktop" (
Copy "C:\document search.website" "\\%MyVar%\c$\Users\Public\Desktop\" /Y
Copy "C:\document search.website" "\\%MyVar%\C$\Users\Public\Favorites\" /Y
) else ( copy "C:\document search.website" "\\%MyVar%\c$\Documents and Settings\All Users\Desktop\Document Search.url" /y
copy "C:\document search.website" "\\%MyVar%\C$\Documents and Settings\All Users\Favorites\Document Search.url" /y
)
答案 0 :(得分:3)
您可以在脚本开头添加以下脚本
call :Logit>>C:\logfiles_location\file_transfer.log 2>&1
:Logit
echo Start time is: %date% %TIME%
答案 1 :(得分:1)
您需要将copy
命令的输出重定向到文件。但是,copy
命令仅打印副本的结果,而不包含文件名(例如1 file(s) copied.
)。因此,您应该使用您正在执行的操作为日志添加额外的日志行。
REM Flush the previous log file
echo. > someLogFile.log
for /f "Tokens=*" %%a in (c:\computers.txt) do (set MyVar=%%a& call :next)
pause
goto EOF
:next
echo %MyVar%
if exist "\\%MyVar%\C$\Users\Public\Desktop" (
echo Copying to %MyVar% desktop... > someLogFile.log
Copy "C:\document search.website" "\\%MyVar%\c$\Users\Public\Desktop\" /Y >> someLogFile.log
echo Copying to %MyVar% favorites... > someLogFile.log
Copy "C:\document search.website" "\\%MyVar%\C$\Users\Public\Favorites\" /Y >> someLogFile.log
) else (
echo Copying to %MyVar% desktop... > someLogFile.log
copy "C:\document search.website" "\\%MyVar%\c$\Documents and Settings\All Users\Desktop\Document Search.url" /y >> someLogFile.log
echo Copying to %MyVar% favorites... > someLogFile.log
copy "C:\document search.website" "\\%MyVar%\C$\Documents and Settings\All Users\Favorites\Document Search.url" /y >> someLogFile.log
)