No commas!

S

Spin

The script below determines the size in bytes of file01.log on Server1. But
what I need is the size in bytes to have comma separators like one normally
writes a big number out, like this:

2,345,124

Right now the script returns the value similar to below w/out commas, making
it a bit harder to read:

2345124

REM This file determines size of file01.log on Server1
@echo off
for /f "tokens=3" %%a in (
'dir /-c \\Server1\d$\file01.log ^| find "/"'
) do set zsize=%%a
for /f "tokens=5" %%a in (
'echo.^|time^|findstr /i "Current"'
) do set ztime=%%a
if "%ztime:~1,1%" EQU ":" set ztime=0%ztime%
set ztime=%ztime:~0,8%
for /f "tokens=*" %%a in (
'date /t'
) do set zdate=%%a
echo file01.log file size on Server1 on %zdate%%ztime% is %zsize% >
D:\Tracker.txt"
 
W

Walter Schulz

echo file01.log file size on Server1 on %zdate%%ztime% is %zsize% >
D:\Tracker.txt"
echo file01.log file size on Server1 on %zdate%%ztime% is %zsize:% >
D:\Tracker.txt"
echo file01.log file size on Server1 on %zdate%%ztime% is
%zsize:~-12,-9%,%zsize:~-9,-6%,%zsize:~-6,-3%,%zsize:~-3% >
D:\Tracker.txt

You may want to create a subroutine to aviod leading commas.

Ciao, Walter
 
M

Mark V

In said:
The script below determines the size in bytes of file01.log on
Server1. But what I need is the size in bytes to have comma
separators like one normally writes a big number out, like this:

2,345,124

Right now the script returns the value similar to below w/out
commas, making it a bit harder to read:

2345124

REM This file determines size of file01.log on Server1
@echo off
for /f "tokens=3" %%a in (
'dir /-c \\Server1\d$\file01.log ^| find "/"'
) do set zsize=%%a
for /f "tokens=5" %%a in (
'echo.^|time^|findstr /i "Current"'
) do set ztime=%%a
if "%ztime:~1,1%" EQU ":" set ztime=0%ztime%
set ztime=%ztime:~0,8%
for /f "tokens=*" %%a in (
'date /t'
) do set zdate=%%a
echo file01.log file size on Server1 on %zdate%%ztime% is %zsize%

I must be missing the point since you specifically use
DIR /-C
to _remove_ the commas....
 
P

Phil Robyn

Spin said:
The script below determines the size in bytes of file01.log on Server1. But
what I need is the size in bytes to have comma separators like one normally
writes a big number out, like this:

2,345,124

Right now the script returns the value similar to below w/out commas, making
it a bit harder to read:

2345124

REM This file determines size of file01.log on Server1
@echo off
for /f "tokens=3" %%a in (
'dir /-c \\Server1\d$\file01.log ^| find "/"'
) do set zsize=%%a
for /f "tokens=5" %%a in (
'echo.^|time^|findstr /i "Current"'
) do set ztime=%%a
if "%ztime:~1,1%" EQU ":" set ztime=0%ztime%
set ztime=%ztime:~0,8%
for /f "tokens=*" %%a in (
'date /t'
) do set zdate=%%a
echo file01.log file size on Server1 on %zdate%%ztime% is %zsize% >
D:\Tracker.txt"

- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>zformat2 1234567890987654321234567890987654321 .
1,234,567,890,987,654,321,234,567,890,987,654,321

C:\cmd>rlist C:\cmd\TEST\zFORMAT2.cmd
=====begin C:\cmd\TEST\zFORMAT2.cmd ====================
01. @echo off
02. ::
03. :: inserts commas in number of any length
04. ::
05. :: examples: 12345678 becomes 12,345,678
06. :: $12345678.99 becomes $12,345,678.99
07. :: 12345678.00172 becomes 12,345,678.00172
08. ::
09. :: result is returned in environment variable %~n0
10. ::
11. :: to DISPLAY the result, enter "." as the second parameter
12. ::
13. if {%1} NEQ {} (if {%1} NEQ {?} (if {%1} NEQ {/?}^
14. (if /i {%1} NEQ {HELP} ( goto :begin ))))
15. call XHELP %~f0
16. goto :EOF
17. :begin
18. setlocal
19. set S001=%1
20.
21. :: remove leading dollar sign, if any
22. if %S001:~0,1%==$ (
23. set currency=yes
24. set S001=%S001:~1%
25. )
26.
27. :: remove fractional portion, if any
28. for /f "tokens=1,2 delims=." %%a in ("%S001%") do set fraction=%%b
29. if defined fraction call set S001=%%S001:.%fraction%=%%%
30.
31. set S002=%S001%
32. set length=0
33. :zsize
34. set /a length+=1
35. set S002=%S002:~1%
36. if defined S002 goto :zsize
37. set /a ctr=-1
38. set out=
39. for /l %%a in (%length%,-1,0) do call :digit %%a
40. if "%out:~0,1%"=="," set out=%out:~1%
41. if defined fraction set out=%out%.%fraction%
42. if defined currency set out=$%out%
43. if "%2"=="." echo %out%
44. endlocal&set %~n0=%out%&goto :EOF
45.
46. :digit
47. set pos=%1
48. set /a ctr+=1
49. if %ctr% EQU 3 set comma=,
50. call set digit=%%S001:~%pos%,1%%%
51. call set out=%comma%%digit%%out%%
52. if defined comma (
53. set comma=
54. set ctr=0
55. )
56. goto :EOF
=====end C:\cmd\TEST\zFORMAT2.cmd ====================
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -
 
S

Spin

Thx.

--

Phil Robyn said:
- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>zformat2 1234567890987654321234567890987654321 .
1,234,567,890,987,654,321,234,567,890,987,654,321

C:\cmd>rlist C:\cmd\TEST\zFORMAT2.cmd
=====begin C:\cmd\TEST\zFORMAT2.cmd ====================
01. @echo off
02. ::
03. :: inserts commas in number of any length
04. ::
05. :: examples: 12345678 becomes 12,345,678
06. :: $12345678.99 becomes $12,345,678.99
07. :: 12345678.00172 becomes 12,345,678.00172
08. ::
09. :: result is returned in environment variable %~n0
10. ::
11. :: to DISPLAY the result, enter "." as the second parameter
12. ::
13. if {%1} NEQ {} (if {%1} NEQ {?} (if {%1} NEQ {/?}^
14. (if /i {%1} NEQ {HELP} ( goto :begin ))))
15. call XHELP %~f0
16. goto :EOF
17. :begin
18. setlocal
19. set S001=%1
20.
21. :: remove leading dollar sign, if any
22. if %S001:~0,1%==$ (
23. set currency=yes
24. set S001=%S001:~1%
25. )
26.
27. :: remove fractional portion, if any
28. for /f "tokens=1,2 delims=." %%a in ("%S001%") do set fraction=%%b
29. if defined fraction call set S001=%%S001:.%fraction%=%%%
30.
31. set S002=%S001%
32. set length=0
33. :zsize
34. set /a length+=1
35. set S002=%S002:~1%
36. if defined S002 goto :zsize
37. set /a ctr=-1
38. set out=
39. for /l %%a in (%length%,-1,0) do call :digit %%a
40. if "%out:~0,1%"=="," set out=%out:~1%
41. if defined fraction set out=%out%.%fraction%
42. if defined currency set out=$%out%
43. if "%2"=="." echo %out%
44. endlocal&set %~n0=%out%&goto :EOF
45.
46. :digit
47. set pos=%1
48. set /a ctr+=1
49. if %ctr% EQU 3 set comma=,
50. call set digit=%%S001:~%pos%,1%%%
51. call set out=%comma%%digit%%out%%
52. if defined comma (
53. set comma=
54. set ctr=0
55. )
56. goto :EOF
=====end C:\cmd\TEST\zFORMAT2.cmd ====================
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
 

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