返回列表 发帖
试试将ps命令换成
(Get-PSDrive -Name 'C')|out-string
然后在bat里提取 ,例如
@echo off
for /f "tokens=1-9 delims= " %%a in ('powershell -Command "(Get-PSDrive -Name 'C')|out-string"') do set "__size=%%c"&if not defined __unit set __unit=%%e
echo  %__size% %__unit%
pause COPY
1

评分人数

TOP

回复 4# hnfeng


   
第一行时因为之前没有定义变量__unit ,因此会通过条件 if not defined __unit ,然后执行 set  __unit ,执行成功后变量  __unit 会被定义
后面的行因为变量 __unit 已经定义了 ,if not defined __unit条件不通过就不执行了 ,这也意味着 ,如果多次使用命令获取磁盘空间时 ,得先删除变量__unit
至于结果 ,是依赖powershell的输出的 ,不知道powershell的输出会不会随着空间的不同而变化 ,GB级别是没问题 ,其他级别的没测试 ,不清楚

TOP

返回列表