2

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 
)
Laf
  • 7,965
  • 4
  • 37
  • 52
Mike
  • 23
  • 1
  • 1
  • 5

2 Answers2

3

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%
demo.b
  • 3,299
  • 2
  • 29
  • 29
  • This is somewhat of the result log I wanted. I am able to see which computer failed the copy or which one succeeded. This may be tough, and may be asking too much, but is there a way to have it strip down to show which computer failed the copy, and to exclude all that have succeeded? – Mike Oct 15 '13 at 16:47
  • I noticed that I had to press Enter on the keyboard to initiate the command after running the batch. – Mike Oct 15 '13 at 16:53
  • I think I needed to press Enter at a point where the batch is in PAUSE. – Mike Oct 15 '13 at 17:09
  • I don't think you need to do anything. i Use a similar script and there is no need to press Enter when the job completes. – demo.b Oct 15 '13 at 17:27
  • I figured out what the problem was. I was looking at the log file, and it was waiting for me to press the Enter key due to the pause command. I removed PAUSE and now it's working like a charm! – Mike Oct 15 '13 at 17:54
1

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
)
Laf
  • 7,965
  • 4
  • 37
  • 52
  • may be it will be easier if you turn on the `echo` ? – npocmaka Oct 15 '13 at 16:46
  • When I tried using this, the log file showed up empty. I tried to modify it a little bit, but nothing seemed to work. demo.b's answer worked to get the results that I needed. It provided a full log of what the command went through. – Mike Oct 15 '13 at 16:50
  • @Mike, I modified it a bit, namely I changed the `>` redirection to a `>>` redirection, to append the text to the log file rather than overwriting it every time. – Laf Oct 15 '13 at 17:37
  • @Laf, this is only recording the last line of the code. I used demo.b's code, and it's working really well. I do appreciate all the assistance, it's not going by unnoticed! – Mike Oct 15 '13 at 18:09