[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-09-05
7
Medium Priority
?
2,030 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 668 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 71

Assisted Solution

by:Qlemo
Qlemo earned 668 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 57

Assisted Solution

by:Bill Prew
Bill Prew earned 664 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress

649 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