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.
I need to write a batch file that will robocopy a group of folders to a list of computers in a text file.
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 ***
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$\Distr ibution" "\\UKIMIV00023883\c$\Distr ibution" /MIR /E
Instead of one machine name UKIMIV00023883 I would like to parse a list compiled in a text file of computers.
Many thanks,
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$\Distr
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$\Distr ibution" "\\%i\c$\Distribution" /MIR /E
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do robocopy "\\%computername%\C$\Distr
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.....
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do copy <filetocopy> %i