Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.bat syntax question

Status
Not open for further replies.

cdeardor

MIS
Oct 25, 2002
49
US
Hello, I'm trying to write a .bat file that will copy a file to several directories based off of a file called commands.txt. On unix, I would just do this using a for loop. I'm new to .bat scripting and it seems to me that you can only pass one command at a time to the for command. Is this true? Is there an easier way to do this? Here's a syntax example of what I would like to do. Notice there are 3 commands at the end. Only the 1st gets executed.

FOR /F "tokens=1,2,3* delims=/ " %%i in (dirlist.txt) do echo cd %%i\%%j\%%k >> commands.txt echo cp %filename% >> commands.txt echo "file copied" >> commands.txt

Any help is greatly appreciated. Thanks in advance!
 
I found the answer. I didn't really see it on the link you sent me, but thanks for that. You're right, that's a very informative site. The solution was basically to seperate your commands by and &. So, to do what I was trying, the command would look like this..

FOR /F "tokens=1,2,3* delims=/ " %%i in (dirlist.txt) do echo cd %%i\%%j\%%k >> commands.txt&echo cp %filename% >> commands.txt&echo "file copied" >> commands.txt

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top