标题: [数值计算] [分享]批处理获取本地磁盘空间保留小数点后边数值 [打印本页]
作者: /zhqsystem/zhq 时间: 2016-1-4 02:49 标题: [分享]批处理获取本地磁盘空间保留小数点后边数值
利用群内pcl提供混编VBS生成,去除所有延迟变量,去除for内tokens分割参数[超出数值范围会出现错误数值],可以合并到其他区域
-
- @echo off&chcp 936
- for /f "delims=" %%i in ('wmic logicaldisk where driveType^="3" get caption^,freespace^,size /value')do if /i not "%%i"=="" (
- for /f "delims=" %%j in ("%%i")do (
- for /f "delims==" %%k in ("%%j")do (
- if /i "%%k"=="caption" (set "#%%j"
- )else if /i "%%k"=="freespace" (set "#%%j"
- for /f "delims==" %%c in ('call echo,%%#%%k%%')do (
- call set "#calc#=%%c"&&call :calc&&for /f "delims==" %%d in ('call echo,[盘符:"%%#caption%%" ][剩余:单位: B "%%#calc_result#%%" ]')do echo,%%d
- call set "#calc#=%%c/1024"&&call :calc&&for /f "delims==" %%d in ('call echo,[盘符:"%%#caption%%" ][剩余:单位:KB "%%#calc_result#%%" ]')do echo,%%d
- call set "#calc#=%%c/1024/1024"&&call :calc&&for /f "delims==" %%d in ('call echo,[盘符:"%%#caption%%" ][剩余:单位:MB "%%#calc_result#%%" ]')do echo,%%d
- call set "#calc#=%%c/1024/1024/1024"&&call :calc&&for /f "delims==" %%d in ('call echo,[盘符:"%%#caption%%" ][剩余:单位:GB "%%#calc_result#%%" ]')do echo,%%d
- )
- )else if /i "%%k"=="size" (set "#%%j"
- for /f "delims==" %%c in ('call echo,%%#%%k%%')do (
- call set "#calc#=%%c"&&call :calc&&for /f "delims==" %%d in ('call echo,[盘符:"%%#caption%%" ][容量:单位: B "%%#calc_result#%%" ]')do echo,%%d
- call set "#calc#=%%c/1024"&&call :calc&&for /f "delims==" %%d in ('call echo,[盘符:"%%#caption%%" ][容量:单位:KB "%%#calc_result#%%" ]')do echo,%%d
- call set "#calc#=%%c/1024/1024"&&call :calc&&for /f "delims==" %%d in ('call echo,[盘符:"%%#caption%%" ][容量:单位:MB "%%#calc_result#%%" ]')do echo,%%d
- call set "#calc#=%%c/1024/1024/1024"&&call :calc&&for /f "delims==" %%d in ('call echo,[盘符:"%%#caption%%" ][容量:单位:GB "%%#calc_result#%%" ]')do echo,%%d
- )
- )
- )
- )
- )
- pause
- goto :eof
- :calc
- for /f "delims=" %%c in ('mshta.exe "vbscript:createobject("scripting.filesystemobject").getstandardstream(1).write(%#calc#%)(close)"') do if /i "%%~nc"=="" (set "#calc_result#=0%%~xc")else (set "#calc_result#=%%~nxc")
- goto :eof
复制代码
作者: cc5511 时间: 2020-8-29 01:10
学习了 谢谢
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |