Hello everyone, first time posting. Ok, I tried to do a "search" for "for /f" and got errors, then tried "for" and of course that got every posting hehe (haven't had my coffee yet).
I hope this is safe to ask, of the postings regarding looping I keep seeing people getting banded acting like someone else.
Ok, here is what I am trying to do. Based off a txt file with a list of pc names or IP's I want to loop a "copy" command. This will copy a install folder to the pc's based off the txt file. I can't seem to get it to work by either not finding the file, incorrect parameter, or it makes a "batch" file on my desktop.. Please see my failed attempts below and laugh...
Please note, I removed any unneeded information with file paths with { }
for /F "tokens=*" %%A in ("C:\{mylocation}\Batch Files\2XPC.txt") do copy "I:\{networklocation}\2x" %%A <-- this one creates a "batch" file on my desktop???
for /F "tokens=*" %%A in (C:\2XPC.txt) do XCOPY "I:\{networklocation}\2x" \\%%A\C$\2x /i %%A <-- this was an attempt to get the variable into a network share path \\_____\C$
Text file looks something like:
mypc01
mypc12
I am sure I am missing something here.. Any help would be great.. Thank you for your time.
For Command to loop issues
Moderator: DosItHelp
Re: For Command to loop issues
Assuming mypc01 is an IP address then try something like this.
Provide further details if it isn't quite right.
Provide further details if it isn't quite right.
Code: Select all
@echo off
for /f "delims=" %%a in (textfile.txt) do (
copy /b "\\server\share\file.exe" "\\%%a\share"
)
Re: For Command to loop issues
Thank you for the fast reply and your time..
Please note, I am on a windows 7 system trying to push the folder to windows xp machines (firewalls off).
I am getting this error:
The system cannot find the file C:\Users\swhitney\Desktop\BatchFiles\2XPC.txt.
Press any key to continue . . .
so, I changed to code to point to the .txt path. Here is how I changed it based on your example.
Now, I also tried your code by leaving the .txt file in same directory as the bat file. Though my bat file does still run in same folder as the txt file..
now, I can get it working on an individual system like this. Note, I created a dialog to allow for input into a variable, %IP_ADDRESS%.
Please note, I am on a windows 7 system trying to push the folder to windows xp machines (firewalls off).
I am getting this error:
The system cannot find the file C:\Users\swhitney\Desktop\BatchFiles\2XPC.txt.
Press any key to continue . . .
so, I changed to code to point to the .txt path. Here is how I changed it based on your example.
Code: Select all
@echo off
for /f "delims=" %%a in (C:\Users\swhitney\Desktop\BatchFiles\2XPC.txt) do (
copy /b "I:\Install\Prod Standard\2x" "\\%%a\c$\2x"
)
Now, I also tried your code by leaving the .txt file in same directory as the bat file. Though my bat file does still run in same folder as the txt file..
Code: Select all
@echo off
for /f "delims=" %%a in (2XPC.txt) do (
copy /b "I:\Install\Prod Standard\2x" "\\%%a\c$\2x"
)
now, I can get it working on an individual system like this. Note, I created a dialog to allow for input into a variable, %IP_ADDRESS%.
Code: Select all
@echo off
ROBOCOPY "I:\Install\Prod Standard\2x" \\%IP_ADDRESS%\C$\2x /S
Re: For Command to loop issues
tragik78 wrote:now, I can get it working on an individual system like this. Note, I created a dialog to allow for input into a variable, %IP_ADDRESS%.Code: Select all
@echo off
ROBOCOPY "I:\Install\Prod Standard\2x" \\%IP_ADDRESS%\C$\2x /S
Then try this. I didn't read properly and didn't notice that you are copying folders rather than just a file.
Code: Select all
@echo off
for /f "delims=" %%a in (C:\Users\swhitney\Desktop\BatchFiles\2XPC.txt) do (
ROBOCOPY "I:\Install\Prod Standard\2x" "\\%%a\C$\2x" /S
)
Re: For Command to loop issues
Thank you Foxidrive, that worked great.. granted my dumby self had my txt file named Name.txt but forgot the extensions were hidden from common files. Thus my txt file was named Name.txt.txt and boy that threw me for a wrench..
Thanks again for all your help!
Thanks again for all your help!