Solved

Batch File: Invalid number. Numbers are limited to 32-bits of precison.

Posted on 2010-09-05
7
1,900 Views
Last Modified: 2012-05-10
Hi there,

I have this script that will not only output the local drives infos, but also convert units to GB.

My problem is when a drive has more than 1TB, I get the following error:
Invalid number. Numbers are limited to 32-bits of precison.

Thanks for your help,
Rene
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

IF EXIST %~n0.txt DEL %~n0.txt

FOR /F "tokens=1-7 delims=," %%A IN ('@WMIC LogicalDisk Where DriveType^=^"3^" Get DeviceID^,DriveType^,FileSystem^,FreeSpace^,Size^,VolumeSerialNumber /Format:csv ^| find ^"3^"') DO (
	REM ECHO %%A %%B %%C %%D %%E %%F %%G
	SET DRIVE=%%B
	SET FreeSpace=%%E
	SET TotalSpace=%%F
	SET /A FreeSpace=!FreeSpace:~0,-3!/1024*1000/1024/1024
	SET /A TotalSpace=!TotalSpace:~0,-3!/1024*1000/1024/1024
	ECHO !DRIVE! !TotalSpace!GB !FreeSpace!GB>>%~n0.txt
	)
PAUSE
EXIT

Open in new window

0
Comment
Question by:ReneGe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 14

Accepted Solution

by:
Psy053 earned 167 total points
ID: 33609465
Have you considered using a VBScript to do it?

strComputer = "."
strFileName = "C:\DiskSpace.log"
Const Gig = 1073741824

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName,8,True)

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk WHERE Drivetype='3'")
Wscript.Echo strComputer
For Each objDisk in colDisks
	objFile.WriteLine objDisk.DeviceID & " " & _
	FormatNumber(objDisk.Size / Gig, 2,,,0)  & " " & _ 
	FormatNumber(objDisk.FreeSpace / Gig, 2,,,0)
Next
objFile.Close

Open in new window

0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 167 total points
ID: 33609472
The limit is 2147483647 (2^32-1). As sson as you use set /A, the string in FreeSpace and TotalSpace will be interpreted as integer, and that causes the overflow.
Just take off more of the digits from the end, as you do already with the 3 byte digits. Depending on the accuracy you want to maintain you can just remove another 3 digits (the KB part):

        SET /A FreeSpace=!FreeSpace:~0,-6!/1024*1000/1024
        SET /A TotalSpace=!TotalSpace:~0,-6!/1024*1000/1024

0
 
LVL 54

Assisted Solution

by:Bill Prew
Bill Prew earned 166 total points
ID: 33610522
Search is your friend Rene :-).

A couple of solid related posts here.  FWIW I think your choices are (a) use a third part util for the math that can handle large numbers, (b) use VB script, either for the whole task, or just create a small helper routine where you pass it the number and it returns the formatted version, or (c) you remove some accuracy and live with an approximation in BAT only code.

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_26414453.html

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_24881845.html

~bp
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 10

Author Comment

by:ReneGe
ID: 33612227
==> bp
According to: http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_26414453.html
I have the same problem, except that I get the error starting at 100GB insted of 1TB.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_24881845.html
Provides me with very unaccurate output

==> Qlemo
SET /A FreeSpace=!FreeSpace:~0,-6!/1024*1000/1024
Provides me with very unaccurate output

==> Psy053
The Script does not work.


Thanks guys for helping,
Rene
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33612249
Like bp and Psy053 suggested, I think I'll have to go for VBScript.

Since it would be better that I'm in the VB section, I'll split the points here, close this thread and open a new one.

I'll provide you it's link.

Thanks guys,
Rene
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33612525
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35133739
Hi guys,

I thought you may be interested into this one.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26886544.html

Thanks and cheers,
Rene
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb example issues 3 88
Run AutoHotkey script directly from Notepad++ 5 228
Is online banking safe? 11 122
Robocopy output remove leading spaces in log file 6 43
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question