如何获得在批处理文件的可用磁盘空间的整数? [英] How to get integer of free disk space in Batch file?
问题描述
我试图让在批处理文件的可用磁盘空间的整数。这是一个我非常简单的code。
I'm trying to get integer of free disk space in Batch file. This is a my (very) simple code.
@echo off
wmic logicaldisk get freespace >> freespace.log
exit
但输出freespace.log文件。
But output in freespace.log file.
FreeSpace
9772687360
57401442304
7346626560
0
0
我只需要和求和挑整数。经过这样的求和输出。
I need to pick integer only and summation. After summation output like this.
74520756224
我在谷歌搜索我的最好的,但我不能找到解决办法。请帮我:)
I search on Google as my best but I can't find solutions. Please help me:)
推荐答案
下面是一个使用混合批次和PowerShell一个确切的解决方案。它真的应该用纯PowerShell中,VBScript中,或JScript来完成。
Here is an exact solution using hybrid batch and powershell. It really should be done with pure powershell, vbscript, or jscript.
非直观的使用令牌和IF语句用来补偿FOR / F和WMIC的UNI code输出之间的怪异互动。
The non-intuitive use of tokens and the IF statement are to compensate for the weird interaction between FOR /F and the unicode output of WMIC.
@echo off
setlocal enableDelayedExpansion
set /a freeSpace=0
for /f "skip=1 tokens=1,2" %%A in ('wmic logicaldisk get freespace') do (
if "%%B" neq "" for /f %%N in ('powershell !freeSpace!+%%A') do (
set freeSpace=%%N
)
)
echo freeSpace=%freeSpace%
这篇关于如何获得在批处理文件的可用磁盘空间的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!