1.

Solve : %%G help?

Answer»

So The PROGRAM is SUPPOSE to ping each computer on the network and then display the name and the average ping in this format:
Code: [Select]\\Computer1
= 10ms
\\Computer2
= 20ms
\\Computer3
= 312ms
to do this I was using 'net view | FIND "\\" >>network.1' to write a list of the computers to a file, then I planned on using 'for /f %%G IN (network.1) DO ( set /a c+=1 & echo %%G >>net%c%.1).
The problem is, that it is writing the whole network list into net0.1 every time instead of posting \\computer1 into net0.1 and \\computer2 into net1.1 and \\computer3 into net2.1. Any Idea's?

whole code:
Code: [Select]@echo off
set c=0

net view | find "\\" >>network.1

for /f %%G IN (network.1) DO (
set /a c+=1
echo %%G >>net%c%.1
)

set m=%c%
set c=0
pause

:loop.rename
set y=\\
set /p y=<net%c%.1
set y=%y:~2,100%
ping %y% | find "Min" >>ping%c%.1
set /a c+=1
if %c% EQU %m% goto break.rename
goto loop.rename
:break.rename

set c=0

:loop.view
type net%c%.1
set /p a=<ping%c%.1
FOR /F "tokens=4 delims==" %%G IN ("%a%") DO (
echo %%G
)
set /a c+=1
if %c% EQU %m% goto break.view
goto loop.view
:break.view

pause
del /f *.1
pause >nul
Code: [Select]for /f "delims=*" %%G in (network.1) do (set /a c+= 1 & echo %%G >>net%c%.1)


See if that helps. You might need to tweak the delims= value if it doesn't.Nope, still gives net0.1 containing
Code: [Select]\\computer1
\\computer2
Need to use Delayed Expansion. Your inside a FOR LOOP.Quote from: Squashman on July 03, 2012, 06:28:29 AM

Need to use Delayed Expansion. Your inside a FOR LOOP.
Still getting the same error. It's suppose to be Code: [Select]setlocal EnableDelayedExpansioncorrect?Quote from: Lemonilla on July 03, 2012, 07:13:40 AM
Still getting the same error.
You are getting an error now. You didn't say anything about getting an error in your previous posts.

Quote from: Squashman on July 03, 2012, 07:19:17 AM
You are getting an error now. You didn't say anything about getting an error in your previous posts.


My bad, was referring to the BUG as an error. I found the problem though. I was trying to write to net%c%.1, when I changed that to net!1!.1 it worked, so I believe that %c% was not UPDATING with my set /a c+=1.
Final code:
Code: [Select]@echo off
set c=0
if exist *.1 del /f *.1
title Network Pinger
setlocal EnableDelayedExpansion
net view | find "\\" >>network.1

for /f %%G IN (network.1) DO (
set /a c+=1
echo %%G >>net!c!.1
)

set m=%c%
set c=0

:loop.rename
set /a c+=1
set y=\\
set /p y=<net!c!.1
set y=%y:~2,100%
ping %y% | find "Min" >>ping%c%.1
if %c% EQU %m% goto break.rename
goto loop.rename
:break.rename

set c=0

:loop.view
set /a c+=1
type net%c%.1
set /p a=<ping%c%.1
FOR /F "tokens=4 delims==" %%G IN ("%a%") DO (
echo %%G
)
if %c% EQU %m% goto break.view
goto loop.view
:break.view

del /f *.1
pause >nul

Quick question, when pinging a computer name, will it be effected by internet usage? (i.e. If I have 120 pictures loading on the internet and ping myself, will the loading of the pictures slow down the packets?)Quote
I believe that %c% was not updating with my set /a c+=1.

For delayed-expansion to work you need two things

1. Setlocal enabledelayedexpansion

2. The variable name to be expanded is preceded and followed by exclamation marks NOT percent signs.


Discussion

No Comment Found