Use Robocopy to copy files and folders to computers lsied in a test file

garcoli
garcoli used Ask the Experts™
on
Hi,

I need to write a batch file that will robocopy a group of folders to a list of computers in a text file.


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Does this work?  Replace <filetocopy> with the name of the file to copy.

FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do copy <filetocopy> %i
 
And myfile.txt with your text file with the computer names.
Farhan KaziSystems Engineer
Top Expert 2007

Commented:
Check following batch script, if this works for you.
@ECHO OFF
SETLOCAL EnableDelayedExpansion

IF NOT EXIST Computers.txt GOTO ShowErr
FOR %%R IN (Computers.txt) DO IF %%~zR EQU 0 GOTO ShowErr

FOR /F %%c in ('TYPE Computers.txt') DO (
ECHO Processing: %%c
    PING -n 1 -w 1000 %%c |FIND /I "TTL" >NUL
	IF NOT ERRORLEVEL 1 (
		Robocopy "C:\DATA" "\\%%c\D$\DATA"
	)ELSE (ECHO *** ERROR *** %%c: System Offline.))

GOTO EndScript

:ShowErr
ECHO 'Computers.txt' file does not exist or file is empty!

:EndScript
ENDLOCAL
:: *** SCRIPT END ***

Open in new window

Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Author

Commented:
Hi,

Thanks for the prompt response, I was hoping to use robocopy as the folder has 1GB of data and I would like to log the robocopy. This is the code I have for copy to one file.

robocopy.exe "\\%computername%\C$\Distribution"  "\\UKIMIV00023883\c$\Distribution" /MIR /E

Instead of one machine name UKIMIV00023883 I would like to parse a list compiled in a text file of computers.

Many thanks,
Then farhankazi has it.  Or you can replace the command in mine:

FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do robocopy  "\\%computername%\C$\Distribution" "\\%i\c$\Distribution" /MIR /E

Author

Commented:
farhankazi

I am doing somthingn wrong here , copied your script word for word and created txt file called computers with an entry and am getting computers text file does not exist or is empty.....
Systems Engineer
Top Expert 2007
Commented:
Make sure computers.txt file and this batch script resides on the same path or you can also specify the path where computer.txt file resides.
Like:

IF NOT EXIST "C:\My Scripts\Computers.txt" GOTO ShowErr
FOR %%R IN ("C:\My Scripts\Computers.txt") DO IF %%~zR EQU 0 GOTO ShowErr

FOR /F %%c in ('TYPE "C:\My Scripts\Computers.txt"') DO (

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial