%%A not translating as variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
technotika
Posts: 10
Joined: 02 Jun 2011 06:22

%%A not translating as variable

#1 Post by technotika » 02 Jun 2011 06:33

Hi ,

I'm struggling to get a batch file to run against a list of hostnames

heres some code where the issue occurs

@echo on
for /f %%A in (C:\hosts.txt) do
xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%%a\C$\Temp"

and here is the error

C:\WINDOWS\system32>xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdm
inistrator-2.0.5.msi" "\\%a\C$\Temp"
Invalid drive specification
0 File(s) copied

As you can see the %%A doesn't bring the computer name listed in the hosts.txt file, where I would expect \\PCNAMEEG\C$\Temp Im getting %A as the pcname and thus the fail. I have played around with different things but cant get to the bottom of it?


Any tips would be great...thanks.

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: %%A not translating as variable

#2 Post by jeb » 02 Jun 2011 06:55

Sometimes it's hard to see ... :)

%%A <> %%a

It's case sensitive

jeb

technotika
Posts: 10
Joined: 02 Jun 2011 06:22

Re: %%A not translating as variable

#3 Post by technotika » 02 Jun 2011 07:09

thanks for quick response...still no joy

code test

@echo on
E:\PsexecTMA>for /F %A in (C:\hosts.txt) do Echo %A

E:\PsexecTMA>Echo COMPNAME <SUCCESS there but.....
Z1012030

xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%%A\C$\Temp"
E:\PsexecTMA>pause
Press any key to continue . . .

E:\PsexecTMA>xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%A\C$\Temp"
Invalid drive specification
0 File(s) copied


ACTUAL CODE
@echo on

for /f %%A in (C:\hosts.txt) do Echo %%A

pause

xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%%A\C$\Temp"

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: %%A not translating as variable

#4 Post by dbenham » 02 Jun 2011 07:19

It looks like you are missing ( ) to group multiple commands in your FOR loop DO section. As originally written your XCOPY line is not part of the FOR loop.

Code: Select all

@echo on
for /f %%A in (C:\hosts.txt) do (
  Echo %%A
  pause
  xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%%A\C$\Temp"
)


Dave Benham

technotika
Posts: 10
Joined: 02 Jun 2011 06:22

Re: %%A not translating as variable

#5 Post by technotika » 02 Jun 2011 07:33

FANTASTIC - thank you very much

So if I have loads of commands to do for each machine in the hosts.txt

as long as I have it all in ( ) It's all good e.g.

@echo off

for /f %%A in (C:\hosts.txt) do (
code code code code code codecode code codecode code codecode code code
pause
code code codecode code codecode code codecode code codecode code code
pause
code code codecode code codecode code codecode code codecode code code
pause
)

Post Reply