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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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

Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

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.....
Farhan KaziSystems 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 (


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.