Share Comment Length

B

Barney

I'm trying to write a script that will report the number
of characters in a share's comment. The comments in
question refer to shared printers on our Windows 2000
Server.

I have the following:

---------- Begin Code Snippet -------------------

FOR /F "Skip=8 Tokens=3*" %%A IN ('NET VIEW
\\PrinerServer') DO (
SET PrinterName=%%A %%B
CALL :CharacterCounter
)

PAUSE


:CharacterCounter
SET Count=0
:Loop
CALL SET Check=!PrinterName:~%Count%,1!
IF DEFINED Check SET /A Count=Count+1 & GOTO :Loop
ECHO/!PrinterName! is %Count% characters long.
GOTO :EOF

---------- End Code Snippet -------------------

This, however, does not work. It reports the share
comment correctly but not the number of character in
the 'field'.

Any suggestions?
 
P

Phil Robyn

Barney said:
I'm trying to write a script that will report the number
of characters in a share's comment. The comments in
question refer to shared printers on our Windows 2000
Server.

I have the following:

---------- Begin Code Snippet -------------------

FOR /F "Skip=8 Tokens=3*" %%A IN ('NET VIEW
\\PrinerServer') DO (
SET PrinterName=%%A %%B
CALL :CharacterCounter
)

PAUSE


:CharacterCounter
SET Count=0
:Loop
CALL SET Check=!PrinterName:~%Count%,1!
IF DEFINED Check SET /A Count=Count+1 & GOTO :Loop
ECHO/!PrinterName! is %Count% characters long.
GOTO :EOF

---------- End Code Snippet -------------------

This, however, does not work. It reports the share
comment correctly but not the number of character in
the 'field'.

Any suggestions?

- - - - - - - - - - begin screen capture WinXP - - - - - - - - - -
C:\cmd>demo\CountCharacters now is the time for all good men
length of 'test' is 32

C:\cmd>ruler 40&echo now is the time for all good men
.....+....1....+....2....+....3....+....4
now is the time for all good men

C:\cmd>rlist demo\CountCharacters.cmd
=====begin C:\cmd\demo\CountCharacters.cmd ====================
1. @echo off
2. setlocal
3. set /a ctr = -1
4. set test=%*
5. :loop
6. set /a ctr += 1
7. set check=!test:~%ctr%,1!
8. if defined check goto :loop
9. echo length of 'test' is %ctr%
=====end C:\cmd\demo\CountCharacters.cmd ====================

C:\cmd>currver ruler qblist
===== begin file c:\cmd\UTIL\ruler.cmd =====
01. @echo off
02. setlocal
03. set base=1
04. set length=%1
05. if not defined length set length=80
06. if %length%==0 (
07. set base=0
08. set length=%2
09. )
10. set /a cols = %length% + 10
11. set /a cols = cols / 10
12. set ruler=
13.
14. FOR /l %%a IN (1,1,%cols%) DO call :doruler %%a
15. if %base%==0 (
16. set ruler=0%ruler%
17. set /a length += 1
18. )
19. call echo %%ruler:~0,%length%%%
20. endlocal&goto :EOF
21.
22. :doruler
23. set num=%1
24. if 10 GTR %num% set ruler=%ruler%....+....%num%
25. if 10 EQU %num% set ruler=%ruler%....+....%num:~1,1%.
26. if 10 LSS %num% set ruler=%ruler%...+....%num%
27. goto :EOF
===== end file c:\cmd\UTIL\ruler.cmd =====
- - - - - - - - - - end screen capture WinXP - - - - - - - - - -
 
P

Paul R. Sadowski [MVP]

Hello, Barney:
On Fri, 11 Feb 2005 11:13:39 -0800: you wrote...

B> I'm trying to write a script that will report the number
B> of characters in a share's comment. The comments in
B> question refer to shared printers on our Windows 2000
B> Server.
B>
B> I have the following:
B>
B> ---------- Begin Code Snippet -------------------
B>
B> FOR /F "Skip=8 Tokens=3*" %%A IN ('NET VIEW
B> \\PrinerServer') DO (
B> SET PrinterName=%%A %%B
B> CALL :CharacterCounter
B> )
B>
B> PAUSE
B>
B> :CharacterCounter
B> SET Count=0
B> :Loop
B> CALL SET Check=!PrinterName:~%Count%,1!
B> IF DEFINED Check SET /A Count=Count+1 & GOTO :Loop
B> ECHO/!PrinterName! is %Count% characters long.
B> GOTO :EOF
B>
B> ---------- End Code Snippet -------------------
B>
B> This, however, does not work. It reports the share
B> comment correctly but not the number of character in
B> the 'field'.

call :StrLen %PrinterName%
echo %PrinterName% is %StrLen% characters in length.
:StrLen
:: Get the length of a string
setlocal & set TmpCnt=%*
if not defined TmpCnt (
set StrLen=0
) else (
:Lenloop
set TmpCnt=%TmpCnt:~1%
set /a StrLen +=1
if defined TmpCnt goto Lenloop
)
endlocal & set StrLen=%StrLen%
goto :EOF

Regards, Paul R. Sadowski [MVP].
 
D

Dean Wells [MVP]

Paste the following into a script and call it from your for-in-do loop
passing the extracted share comment as the argument(s).

-----
@echo off
setlocal ENABLEDELAYEDEXPANSION

if "%*"=="" (
set CNT=0
) else (
for /f "delims=[] tokens=1" %%l in (
'cmd /u /c echo %*^| find /v /n ""'
) do (
set /a CNT=%%l-3
)
)

echo %CNT%
 
J

Jerold Schulman

See tip 7431 in the 'Tips & Tricks' at http://www.jsiinc.com

---------- Begin Code Snippet -------------------
@echo off
setlocal ENABLEDELAYEDEXPANSION
FOR /F "Tokens=1,2*" %%A IN ('NET VIEW \\PrintServer^|FIND "Print"') DO (
SET ShareName=%%A
SET PrinterName=%%C#
SET PrinterName=!PrinterName: =!
SET PrinterName=!PrinterName: #=!
SET PrinterName=!PrinterName:#=!
CALL :CharacterCounter PrinterName Count
@echo !ShareName! - !PrinterName! is !Count! characters long.
)

PAUSE

endlocal
goto :EOF
:CharacterCounter
set /a %2 = 0
call echo.%%%1%%>%TEMP%\$VarLen$.tmp
for %%n in (%TEMP%\$VarLen$.tmp) do set /a %2 = %%~zn - 2
del /q %TEMP%\$VarLen$.tmp
goto :EOF
---------- End Code Snippet -------------------












I'm trying to write a script that will report the number
of characters in a share's comment. The comments in
question refer to shared printers on our Windows 2000
Server.

I have the following:

---------- Begin Code Snippet -------------------

FOR /F "Skip=8 Tokens=3*" %%A IN ('NET VIEW
\\PrinerServer') DO (
SET PrinterName=%%A %%B
CALL :CharacterCounter
)

PAUSE


:CharacterCounter
SET Count=0
:Loop
CALL SET Check=!PrinterName:~%Count%,1!
IF DEFINED Check SET /A Count=Count+1 & GOTO :Loop
ECHO/!PrinterName! is %Count% characters long.
GOTO :EOF

---------- End Code Snippet -------------------

This, however, does not work. It reports the share
comment correctly but not the number of character in
the 'field'.

Any suggestions?


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
B

Barney

Thanks to all for your time and efforts. There are some
good ideas and code here. It will take some time for me
to understand it all. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top