获取的&QUOT自由空间; C:"开车使用批处理文件 [英] Get free space of "C:" drive using batch file

查看:117
本文介绍了获取的&QUOT自由空间; C:"开车使用批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  在CMD 自由空间外壳

我想编写一个批处理文件,让我留在C盘的可用空间。
任何帮助将是巨大的。

I want to write a batch file which gives me free space left in C drive. Any help will be great

推荐答案

下面的脚本会给你的驱动器上免费字节:

The following script will give you free bytes on the drive:

@setlocal enableextensions enabledelayedexpansion
@echo off
for /f "tokens=3" %%a in ('dir c:\') do (
    set bytesfree=%%a
)
set bytesfree=%bytesfree:,=%
echo %bytesfree%
endlocal && set bytesfree=%bytesfree%

请注意,这取决于你的 DIR 命令的输出,需要含有格式 24迪尔的自由空间中的最后一行(S )34071691264字节的免费。具体做法是:

Note that this depends on the output of your dir command, which needs the last line containing the free space of the format 24 Dir(s) 34,071,691,264 bytes free. Specifically:


  • 它必须是最后一行(或者你可以修改循环来检测线路明确,而不是依靠设置 bytesfree 每行)。

  • 的自由空间必须是第三个字(或者你可以修改令牌= 位来得到不同的字)。

  • 千位分隔符是字符(或你可以改变从逗号别的东西替代)。

  • it must be the last line (or you can modify the for loop to detect the line explicitly rather than relying on setting bytesfree for every line).
  • the free space must be the third "word" (or you can change the tokens= bit to get a different word).
  • thousands separators are the , character (or you can change the substitution from comma to something else).

,不污染环境的命名空间,只将 bytesfree 退出变量。如果你的 DIR 输出是不同的(例如,不同的区域设置或语言设置),则需要调整脚本。

It doesn't pollute your environment namespace, setting only the bytesfree variable on exit. If your dir output is different (eg, different locale or language settings), you will need to adjust the script.

这篇关于获取的&QUOT自由空间; C:"开车使用批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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