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


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

Who is Participating?
Farhan KaziConnect With a Mentor Systems EngineerCommented:
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.

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 (

Bryan ButlerCommented:
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
Bryan ButlerCommented:
And myfile.txt with your text file with the computer names.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Farhan KaziSystems EngineerCommented:
Check following batch script, if this works for you.
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
		Robocopy "C:\DATA" "\\%%c\D$\DATA"
	)ELSE (ECHO *** ERROR *** %%c: System Offline.))

GOTO EndScript

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

:: *** SCRIPT END ***

Open in new window

garcoliAuthor Commented:

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,
Bryan ButlerCommented:
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
garcoliAuthor Commented:

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.....
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.