[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] 批处理如何查询磁盘空间并输出TXT?

  1. @echo off&title D盘容量使用情况
  2. >DiskCalc1.vbs echo WSCript.Echo "盘符" ^& Chr(9) ^& "总容量(GB)" ^& Chr(9) ^& "已用空间(GB)" ^& Chr(9) ^& "剩余空间(GB)" ^& Chr(9) ^& "使用率"
  3. >DiskCalc2.vbs echo DeviceID = Wscript.Arguments(0)
  4. >>DiskCalc2.vbs echo SizeAvail = Wscript.Arguments(1) / (1024 * 1024 * 1024)
  5. >>DiskCalc2.vbs echo SizeTotal = Wscript.Arguments(2) / (1024 * 1024 * 1024)
  6. >>DiskCalc2.vbs echo SizeUsed = SizeTotal - SizeAvail
  7. >>DiskCalc2.vbs echo SizeRate = SizeUsed / SizeTotal * 100
  8. >>DiskCalc2.vbs echo WSCript.Echo DeviceID ^& Chr(9) ^& Round(SizeTotal,1) ^& Chr(9) ^& Chr(9) ^& Round(SizeUsed,1) ^& Chr(9) ^& Chr(9) ^& _
  9. >>DiskCalc2.vbs echo Round(SizeAvail,1) ^& Chr(9) ^& Chr(9) ^& Round(SizeRate,1) ^& "%%"
  10. cscript //nologo DiskCalc1.vbs
  11. (for /f "tokens=1-3" %%a in ('wmic LogicalDisk where "DeviceID='D:'" get DeviceID ^, Size ^, FreeSpace ^| findstr ":"') do (
  12.     cscript //nologo DiskCalc2.vbs %%a %%b %%c
  13. ))
  14. del DiskCalc*.vbs
  15. echo,&pause
复制代码
网上找了个接近的,但是想实现查询所有盘符情况,并按日期命名输出TXT。不知道怎么实现。感谢 感谢

本帖最后由 窄口牛 于 2017-8-17 12:54 编辑

  1. @echo off&title 各盘容量使用情况
  2. set m=%date:~0,4%%date:~5,2%%date:~8,2%
  3. >DiskCalc1.vbs echo WSCript.Echo "盘符" ^& Chr(9) ^& "总容量(GB)" ^& Chr(9) ^& "已用空间(GB)" ^& Chr(9) ^& "剩余空间(GB)" ^& Chr(9) ^& "使用率"
  4. >DiskCalc2.vbs echo DeviceID = Wscript.Arguments(0)
  5. >>DiskCalc2.vbs echo SizeAvail = Wscript.Arguments(1) / (1024 * 1024 * 1024)
  6. >>DiskCalc2.vbs echo SizeTotal = Wscript.Arguments(2) / (1024 * 1024 * 1024)
  7. >>DiskCalc2.vbs echo SizeUsed = SizeTotal - SizeAvail
  8. >>DiskCalc2.vbs echo SizeRate = SizeUsed / SizeTotal * 100
  9. >>DiskCalc2.vbs echo WSCript.Echo DeviceID ^& Chr(9) ^& Round(SizeTotal,1) ^& Chr(9) ^& Chr(9) ^& Round(SizeUsed,1) ^& Chr(9) ^& Chr(9) ^& _
  10. >>DiskCalc2.vbs echo Round(SizeAvail,1) ^& Chr(9) ^& Chr(9) ^& Round(SizeRate,1) ^& "%%"
  11. cscript //nologo DiskCalc1.vbs >>%m%.txt
  12. for %%l in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
  13. (for /f "tokens=1-3" %%a in ('wmic LogicalDisk where "DeviceID='%%l:'" get DeviceID ^, Size ^, FreeSpace ^| findstr ":"') do (
  14.     cscript //nologo DiskCalc2.vbs %%a %%b %%c >>%m%.txt
  15. )))
  16. del DiskCalc*.vbs
复制代码

TOP

test.bat
  1. @echo off
  2. powershell -f test.ps1 > 1.txt
复制代码
test.ps1
  1. gwmi win32_logicaldisk -filter "drivetype = 3" | % {
  2.     $_.deviceid + "`t" + `
  3.     ($_.size/1GB).tostring("f2") + "`t`t" + `
  4.     ($_.freespace/1GB).tostring("f2") + "`t`t" + `
  5.     ($_.size/1GB-$_.freespace/1GB).tostring("f2") + "`t`t" + `
  6.     (($_.size-$_.freespace)/$_.size*100).tostring("f2") + "%"
  7. }
复制代码
环境所限,需要使用 PowerShell 2.0 版本。

TOP

返回列表