Link to home
Start Free TrialLog in
Avatar of garcoli
garcoli

asked on

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

Hi,

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


Avatar of Bryan Butler
Bryan Butler
Flag of United States of America image

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

Avatar of garcoli
garcoli

ASKER

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
Avatar of garcoli

ASKER

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.....
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial