Link to home
Start Free TrialLog in
Avatar of budchawla
budchawlaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Loop in a batch file, and increment a UNC path

Hi ..
I need to copy a file from my server onto 50 computers, each one is named computer-01, computer-02... computer-50.
How can I do this via a batch file without copy/pasting the line 50 times?!

copy \\server\file.xyz \\computer-01\c$\progra~1\whateverfolder\

I'm sure this is quite simple, but I haven't got a massive amount of experience with batch file scripting!

Thanks!
SOLUTION
Avatar of Nat_c
Nat_c

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

ASKER

Hi Nat,

All makes sense to me.. but I just tried it by creating a batch file in the root of c: with the following:
for /l %n in (1,1,8) do md dir%n
exactly as you said, and I get a message saying the syntax of the command is incorrect?
funny thing, if I run the command itself from the prompt, no problem...
aha... if I type the whole filename at the prompt, (type in md.bat rather than just md) I get a different message:

n was unexpected at this time.

Any ideas?
ASKER CERTIFIED SOLUTION
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
Also, do you know of a good syntax reference for this kind of thing?
Sorry inserted extra space in your md command:

for /l %%n in (1,1,8) do if not exist "dir%%n" md dir%%n

Added a check to see if the directory exists to make up for my mistake :)
aha .. that's it, thanks SteveGTR...
You can type /? for any command on the command prompt. For example:

for /?

or

if /?

I use that all the time. Also, this site has a bunch of good information on batch processing:

http://www.robvanderwoude.com/index.html
Avatar of Nat_c
Nat_c

You can type "help for" at the command prompt and it will tell you all the syntax
thanks guys.. both resources useful!