Create a log file from a copy batch file
Solution 1
you can add the script below at the beginning of your script
call :Logit>>C:\logfiles_location\file_transfer.log 2>&1
:Logit
echo Start time is: %date% %TIME%
Solution 2
You need to redirect the output of the copy
command to a file. However, the copy
command will only print the result of the copy, without the file name included (e.g. 1 file(s) copied.
). So, you should add an extra log line to your log with the action you are doing.
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
)
Mike
Updated on June 05, 2022Comments
-
Mike almost 2 years
I have a COPY batch file that copies a file to multiple computers (about 300, which is being read from a separate text file), and I would like to see the results of the file copy. If I can see both the successful and failed file copies, that would be great. But it'll be fine if it's only possible to see the failed copies.
Here's the code that I have now, which is working great. The files are being copied to the test computers I have setup. Thank you all in advance for taking the time to help me out with this.
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 )