Windows批处理文件,以获得C:\\盘总空间和可用空间 [英] Windows batch file to get C:\ drive total space and free space available

查看:897
本文介绍了Windows批处理文件,以获得C:\\盘总空间和可用空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个bat文件,以获得C:\\驱动器可用的总空间和自由空间,以GB(千兆字节)在Windows系统中,并创建详细信息的文本文件

I need a bat file to get C:\ drive total space and free space available in GB (giga bytes) in a Windows system and create a text file with the details.

请注意:我不想使用任何外部应用

Note: i dont want to use any external utilities.

推荐答案

削减规模的9位数字的字节来获得尺寸GB:

cut 9 digits of the size by bytes to get the size in GB:

@echo off & setlocal ENABLEDELAYEDEXPANSION
SET "volume=C:"
FOR /f "tokens=1*delims=:" %%i IN ('fsutil volume diskfree %volume%') DO (
    SET "diskfree=!disktotal!"
    SET "disktotal=!diskavail!"
    SET "diskavail=%%j"
)
FOR /f "tokens=1,2" %%i IN ("%disktotal% %diskavail%") DO SET "disktotal=%%i"& SET "diskavail=%%j"
(ECHO(Information for volume %volume%
ECHO(total  %disktotal:~0,-9% GB
ECHO(avail. %diskavail:~0,-9% GB)>size.txt
TYPE size.txt

CMD可以用数字只能计算到 2 ^ 31-1 (2,147,483,647〜2.000001千兆字节)

cmd can calculate only with numbers up to 2^31-1   (2,147,483,647 ~ 2.000001 Gigabytes)

这篇关于Windows批处理文件,以获得C:\\盘总空间和可用空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆