Board logo

标题: [系统相关] 批处理如何查询磁盘空间并输出TXT? [打印本页]

作者: elen    时间: 2017-8-17 11:00     标题: 批处理如何查询磁盘空间并输出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:25

本帖最后由 窄口牛 于 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
复制代码

作者: PS2.0    时间: 2017-8-17 15:37

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. }
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2