troubleshooting Question

Batch Loop Through Array of Variables

Avatar of madasczik
madasczik asked on
Microsoft DOS
3 Comments1 Solution2855 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros