Batch file 无效号码。数字的精度限制为32位
在网上找到这个脚本。这是我下载它的基本原因。但我想知道几件事:Batch file 无效号码。数字的精度限制为32位,batch-file,cmd,numbers,integer,numeric,Batch File,Cmd,Numbers,Integer,Numeric,在网上找到这个脚本。这是我下载它的基本原因。但我想知道几件事: 当脚本试图将字节划分为KB、MG和GB时,会出现错误 无效号码。数字的精度限制为32位 文件和目录的总数缺少右括号 代码: c: cd\ @Echo ------------------------------------------------------ @Echo ------------------------------------------------------ @For /F "tokens=*" %%a IN (
c:
cd\
@Echo ------------------------------------------------------
@Echo ------------------------------------------------------
@For /F "tokens=*" %%a IN ('"hostname"') do @Set summaryouthost=%%a
@Echo Integrity Check on: %summaryouthost%
@For /F "tokens=*" %%a IN ('"chdir"') do @Set summaryoutchdir=%%a
@Echo Integrity Check For the path: %summaryoutchdir%
@Echo ------------------------------------------------------
@For /F "tokens=*" %%a IN ('"date /T"') do @Set summaryoutsdate=%%a
@Echo Start Date: %summaryoutsdate%
@For /F "tokens=*" %%a IN ('"time /T"') do @Set summaryoutstime=%%a
@Echo Start time: %summaryoutstime%
@Echo ------------------------------------------------------
@For /F "tokens=*" %%a IN ('"dir /s /-c | find "bytes" | find /v "free""') do @Set summaryout=%%a
::@Echo %summaryout%
@For /f "tokens=1,2 delims=)" %%a in ("%summaryout%") do @set filesout=%%a&set sizeout=%%b
@For /f "tokens=*" %%a IN ('"dir /s /-c | find "bytes free""') do @Set summaryoutdir=%%a
::@Echo %summaryoutdir%
@For /f "tokens=1,2 delims=)" %%a in ("%summaryoutdir%") do @set filesoutdir=%%a&set sizeoutdir=%%b
@Set sizeout=%sizeout:bytes=%
::@Echo %sizeout%
@Set sizeout=%sizeout: =%
@set /A inbytes=%sizeout%
@set /A inkb=(%sizeout%) / 1024
@set /A inmb=(%sizeout%) / (1024*1024)
@set /A ingb=(%sizeout%) / (1024*1024*1024)
@For /F "tokens=*" %%a IN ('"date /T"') do @Set summaryoutedate=%%a
@Echo End Date: %summaryoutedate%
@For /F "tokens=*" %%a IN ('"time /T"') do @Set summaryoutetime=%%a
@Echo End time: %summaryoutetime%
@Echo ------------------------------------------------------
@Echo Total Number of Files is:%filesout%
@Echo Total Number of Directory is: %filesoutdir%
@Set sizeoutdir=%sizeoutdir:bytes=%
::@Echo %sizeoutdir%
@Set sizeoutdir=%sizeoutdir: =%
@Echo ------------------------------------------------------
@Echo Total Size is (BY) :%sizeout%
@Echo Total Size is (KB) :%inkb%
@Echo Total Size is (MB) :%inmb%
@Echo Total Size is (GB) :%ingb%
@Echo ------------------------------------------------------
@Echo Free Space is :%sizeoutdir%
@Echo ------------------------------------------------------
@Echo ------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
Integrity Check on: Laptop01
Integrity Check For the path: C:\
------------------------------------------------------
Start Date: Sun 10/04/2015
Start time: 12:34 AM
------------------------------------------------------
Invalid number. Numbers are limited to 32-bits of presision.
Invalid number. Numbers are limited to 32-bits of presision.
Invalid number. Numbers are limited to 32-bits of presision.
Invalid number. Numbers are limited to 32-bits of presision.
End Date: Sun 10/04/2015
End time: 12:36 AM
------------------------------------------------------
Total Number of Files is:333914 File(s
Total Number of Directory is: 185869 Dir(s
------------------------------------------------------
Total Size is (BY) :248159912076
Total Size is (KB) :
Total Size is (MB) :
Total Size is (GB) :
------------------------------------------------------
Free Space is :625324642304free
------------------------------------------------------
------------------------------------------------------
输出:
c:
cd\
@Echo ------------------------------------------------------
@Echo ------------------------------------------------------
@For /F "tokens=*" %%a IN ('"hostname"') do @Set summaryouthost=%%a
@Echo Integrity Check on: %summaryouthost%
@For /F "tokens=*" %%a IN ('"chdir"') do @Set summaryoutchdir=%%a
@Echo Integrity Check For the path: %summaryoutchdir%
@Echo ------------------------------------------------------
@For /F "tokens=*" %%a IN ('"date /T"') do @Set summaryoutsdate=%%a
@Echo Start Date: %summaryoutsdate%
@For /F "tokens=*" %%a IN ('"time /T"') do @Set summaryoutstime=%%a
@Echo Start time: %summaryoutstime%
@Echo ------------------------------------------------------
@For /F "tokens=*" %%a IN ('"dir /s /-c | find "bytes" | find /v "free""') do @Set summaryout=%%a
::@Echo %summaryout%
@For /f "tokens=1,2 delims=)" %%a in ("%summaryout%") do @set filesout=%%a&set sizeout=%%b
@For /f "tokens=*" %%a IN ('"dir /s /-c | find "bytes free""') do @Set summaryoutdir=%%a
::@Echo %summaryoutdir%
@For /f "tokens=1,2 delims=)" %%a in ("%summaryoutdir%") do @set filesoutdir=%%a&set sizeoutdir=%%b
@Set sizeout=%sizeout:bytes=%
::@Echo %sizeout%
@Set sizeout=%sizeout: =%
@set /A inbytes=%sizeout%
@set /A inkb=(%sizeout%) / 1024
@set /A inmb=(%sizeout%) / (1024*1024)
@set /A ingb=(%sizeout%) / (1024*1024*1024)
@For /F "tokens=*" %%a IN ('"date /T"') do @Set summaryoutedate=%%a
@Echo End Date: %summaryoutedate%
@For /F "tokens=*" %%a IN ('"time /T"') do @Set summaryoutetime=%%a
@Echo End time: %summaryoutetime%
@Echo ------------------------------------------------------
@Echo Total Number of Files is:%filesout%
@Echo Total Number of Directory is: %filesoutdir%
@Set sizeoutdir=%sizeoutdir:bytes=%
::@Echo %sizeoutdir%
@Set sizeoutdir=%sizeoutdir: =%
@Echo ------------------------------------------------------
@Echo Total Size is (BY) :%sizeout%
@Echo Total Size is (KB) :%inkb%
@Echo Total Size is (MB) :%inmb%
@Echo Total Size is (GB) :%ingb%
@Echo ------------------------------------------------------
@Echo Free Space is :%sizeoutdir%
@Echo ------------------------------------------------------
@Echo ------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
Integrity Check on: Laptop01
Integrity Check For the path: C:\
------------------------------------------------------
Start Date: Sun 10/04/2015
Start time: 12:34 AM
------------------------------------------------------
Invalid number. Numbers are limited to 32-bits of presision.
Invalid number. Numbers are limited to 32-bits of presision.
Invalid number. Numbers are limited to 32-bits of presision.
Invalid number. Numbers are limited to 32-bits of presision.
End Date: Sun 10/04/2015
End time: 12:36 AM
------------------------------------------------------
Total Number of Files is:333914 File(s
Total Number of Directory is: 185869 Dir(s
------------------------------------------------------
Total Size is (BY) :248159912076
Total Size is (KB) :
Total Size is (MB) :
Total Size is (GB) :
------------------------------------------------------
Free Space is :625324642304free
------------------------------------------------------
------------------------------------------------------
提前感谢您的帮助。数字精度限制为32位。
这是set/a
的限制
有关变通方法,请参阅下面的“变通方法:32位”
算术表达式(集合/a)
所有数字都必须在32位有符号整数的范围内
数字(-2147483648到2147483647)以处理较大的
数字使用PowerShell或VBScript
来源
解决方法:32位 32位限制的解决方法包括:
进一步阅读
- -对于所有与Windows命令行相关的内容都是一个很好的参考
- -显示、设置或删除CMD环境变量。使用SET所做的更改将仅在当前CMD会话期间保留
- 如果您需要一个简单的磁盘空间欺骗,您可以通过将字符串子集并除以近似值来进行更粗略的计算。像这样:
@set /A ingb=%sizeout:~0,-7% / (1074)
其中%sizeout:~0,-7%子字符串sizeout,这是一种粗略的除以1.000.000的方法,无需处理任何舍入问题,
其中1074计算为1024*1024*1024/1.000.000
对于您需要的所有大小(KB和MB),也会执行相同的操作
MB:%sizeout:~0,-4%/1049
KB:%sizeout:~0,-4%
当然,测量单位越低,数字就越不准确,但对于GB来说,我用它来监控机器上的磁盘空间是非常准确的
我意识到所有这些都可以从DavidPostill的答案中扣除,但我只想提供一个适用于这种特定情况的复制粘贴示例。以及更好的解决方案 对于大小不超过几GB的设备,精确到mb的精度 阅读代码中的备注,以便更好地理解
@echo off
setlocal enabledelayedexpansion
:: Asign filesize to a string variable
set FileSizeString=%~z1
:: Get the lenght of the string
for /L %%x in (1,1,25) do ( if "!FileSizeString:~%%x!"=="" set /a "Lenght=%%x" & goto LenghtResult )
:LenghtResult
rem If lenght of the filesize string is below or equal 9. Numbers: 0 - 999,999,999
if !Lenght! leq 9 (set /a SizeMb=!FileSizeString!/1024/1024
rem If lenght of the filesize string is not below or equal 9 then remove its last 3 characters
) else (set FileSizeString=!FileSizeString:~0,-3!)
rem If lenght of the filesize string is equal 10. Numbers: 1,000,000,000 - 9,999,999,999
if !Lenght! equ 10 (
rem If first character of the filesize string is equal 1. Numbers: 1,000,000,000 - 1,999,999,999
if "!FileSizeString:~0,1!" equ "1" (set /a SizeMb=!FileSizeString!/1049
rem If first character of the filesize string is not equal 1. Numbers: 2,000,000,000 - 9,999,999,999
) else (set /a SizeMb=!FileSizeString!/1074) )
rem If lenght of the filesize string is above or equal 11. Numbers: 10,000,000,000 - 999,999,999,999,999...
if !Lenght! geq 11 (set /a SizeMb=!FileSizeString!/1074)
:: Displays file name and it's size in mb
echo.
echo File: %~nx1
echo Size: !SizeMb!mb
下面将获得gig中的总物理内存
@echo off
Rem This will produce a file for total ram
Wmic Computersystem get totalphysicalmemory > c:\temp\trash\allram1.txt
Rem This will produce a clean text file with true value
type c:\temp\trash\allram1.txt > c:\temp\trash\allram3.txt
REm The following will skip a line (header)
( for /F usebackq^ skip^=1^ delims^=^ eol^= %%L in ("c:\temp\trash\allram3.txt") do echo(%%L) > "c:\temp\trash\allram4.txt"
Rem following will produce a clean file with actual number
setlocal enabledelayedexpansion
set /p val=<c:\temp\trash\allram4.txt
set newval=!val:~10,1!
rem it will find the new value wheter it is more than 10 gig
echo !newval! > c:\temp\trash\allram2.txt
rem This will determine if more than 10 gig is found (less than 10 gig) (more than 10 gig)
findstr "off" c:\temp\trash\allram2.txt && (set newval2=!val:~0,1!.!val:~1,1!) || (set newval2= !val:~0,2!)
rem if it is less than 10 gig it will have decimal for example 8.2gig or 17gig (if it is more 10 gig)
echo !newval2!gig
@echo关闭
Rem这将为总ram生成一个文件
Wmic Computersystem get totalphysicalmemory>c:\temp\trash\allram1.txt
Rem这将生成一个具有真值的干净文本文件
键入c:\temp\trash\allram1.txt>c:\temp\trash\allram3.txt
REm以下内容将跳过一行(标题)
(对于/F usebackq^skip^=1^delims^=^eol^=%%L在(“c:\temp\trash\allram3.txt”)中执行echo(%%L)>“c:\temp\trash\allram4.txt”
Rem following将生成一个带有实际编号的干净文件
setlocal enabledelayedexpansion
set/p val=c:\temp\trash\allram2.txt
rem这将确定是否发现超过10千兆(小于10千兆)(大于10千兆)
findstr“off”c:\temp\trash\allram2.txt&&(set newval2=!val:~0,1!。!val:~1,1!)|(set newval2=!val:~0,2!)
rem如果小于10 gig,它将具有十进制,例如8.2gig或17gig(如果大于10 gig)
echo!newval2!gig
任何超过大约3Gb的文件大小都将超过32位整数大小。@Granity-实际上限制为2Gb。缺少文件和文件夹总数的结束符,因为代码只是删除它们;因此您需要手动附加它们。。。