Link to home
Start Free TrialLog in
Avatar of madasczik
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%FolderNotToCopy
set retryAttempts=2400
set retryWait=30
set logFile=c:\Temp\FileTransfers\ecom_deployments-%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%\MyDestinationPath\
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%\MyDestinationPath\
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%\MyDestinationPath\
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
Avatar of SteveGTR
SteveGTR
Flag of United States of America 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
Could compact for loop like so if you want to process more IP's:

for /L %%a in (61, 1, 63) do echo call ::PROCESS 192.168.1.%%a
Avatar of madasczik
madasczik

ASKER

Thanks, works like a charm.