madasczik
asked on
Batch Loop Through Array of Variables
How can I condense this code so it loops through an array or variables in a batch file?
@echo off
REM --- Get Date
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i-%%j-%%k-%%l
REM --- Robocopy Parameters
set source=D:\MySourcePath\
set folderExemption=%Source%Fo lderNotToC opy
set retryAttempts=2400
set retryWait=30
set logFile=c:\Temp\FileTransf ers\ecom_d eployments -%dt%.log
REM --- My Set of IPs to Connect to
set IP1=\\192.168.1.61
set IP2=\\192.168.1.62
set IP3=\\192.168.1.63
REM --- The 1st Set
set destination=%IP1%\MyDestin ationPath\
net use %IP1%\ipc$ /user:username password
Robocopy %Source% %Destination% /E /ZB /COPY:DAT /XD %folderExemption% /R:%retryAttempts% /W:%retryWait% /TS /NC /NP /LOG+:%logFile%
net use %IP1%\ipc$ /del
REM --- The 2nd Set
set destination=%IP2%\MyDestin ationPath\
net use %IP2%\ipc$ /user:username password
Robocopy %Source% %Destination% /E /ZB /COPY:DAT /XD %folderExemption% /R:%retryAttempts% /W:%retryWait% /TS /NC /NP /LOG+:%logFile%
net use %IP2%\ipc$ /del
REM --- The 3rd Set
set destination=%IP3%\MyDestin ationPath\
net use %IP3%\ipc$ /user:username password
Robocopy %Source% %Destination% /E /ZB /COPY:DAT /XD %folderExemption% /R:%retryAttempts% /W:%retryWait% /TS /NC /NP /LOG+:%logFile%
net use %IP3%\ipc$ /del
@echo off
REM --- Get Date
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i-%%j-%%k-%%l
REM --- Robocopy Parameters
set source=D:\MySourcePath\
set folderExemption=%Source%Fo
set retryAttempts=2400
set retryWait=30
set logFile=c:\Temp\FileTransf
REM --- My Set of IPs to Connect to
set IP1=\\192.168.1.61
set IP2=\\192.168.1.62
set IP3=\\192.168.1.63
REM --- The 1st Set
set destination=%IP1%\MyDestin
net use %IP1%\ipc$ /user:username password
Robocopy %Source% %Destination% /E /ZB /COPY:DAT /XD %folderExemption% /R:%retryAttempts% /W:%retryWait% /TS /NC /NP /LOG+:%logFile%
net use %IP1%\ipc$ /del
REM --- The 2nd Set
set destination=%IP2%\MyDestin
net use %IP2%\ipc$ /user:username password
Robocopy %Source% %Destination% /E /ZB /COPY:DAT /XD %folderExemption% /R:%retryAttempts% /W:%retryWait% /TS /NC /NP /LOG+:%logFile%
net use %IP2%\ipc$ /del
REM --- The 3rd Set
set destination=%IP3%\MyDestin
net use %IP3%\ipc$ /user:username password
Robocopy %Source% %Destination% /E /ZB /COPY:DAT /XD %folderExemption% /R:%retryAttempts% /W:%retryWait% /TS /NC /NP /LOG+:%logFile%
net use %IP3%\ipc$ /del
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, works like a charm.
for /L %%a in (61, 1, 63) do echo call ::PROCESS 192.168.1.%%a