标题: [系统相关] 批处理如何查询磁盘空间并输出TXT? [打印本页]
作者: elen 时间: 2017-8-17 11:00 标题: 批处理如何查询磁盘空间并输出TXT?
- @echo off&title D盘容量使用情况
- >DiskCalc1.vbs echo WSCript.Echo "盘符" ^& Chr(9) ^& "总容量(GB)" ^& Chr(9) ^& "已用空间(GB)" ^& Chr(9) ^& "剩余空间(GB)" ^& Chr(9) ^& "使用率"
- >DiskCalc2.vbs echo DeviceID = Wscript.Arguments(0)
- >>DiskCalc2.vbs echo SizeAvail = Wscript.Arguments(1) / (1024 * 1024 * 1024)
- >>DiskCalc2.vbs echo SizeTotal = Wscript.Arguments(2) / (1024 * 1024 * 1024)
- >>DiskCalc2.vbs echo SizeUsed = SizeTotal - SizeAvail
- >>DiskCalc2.vbs echo SizeRate = SizeUsed / SizeTotal * 100
- >>DiskCalc2.vbs echo WSCript.Echo DeviceID ^& Chr(9) ^& Round(SizeTotal,1) ^& Chr(9) ^& Chr(9) ^& Round(SizeUsed,1) ^& Chr(9) ^& Chr(9) ^& _
- >>DiskCalc2.vbs echo Round(SizeAvail,1) ^& Chr(9) ^& Chr(9) ^& Round(SizeRate,1) ^& "%%"
- cscript //nologo DiskCalc1.vbs
- (for /f "tokens=1-3" %%a in ('wmic LogicalDisk where "DeviceID='D:'" get DeviceID ^, Size ^, FreeSpace ^| findstr ":"') do (
- cscript //nologo DiskCalc2.vbs %%a %%b %%c
- ))
- del DiskCalc*.vbs
- echo,&pause
复制代码
网上找了个接近的,但是想实现查询所有盘符情况,并按日期命名输出TXT。不知道怎么实现。感谢 感谢
作者: 窄口牛 时间: 2017-8-17 12:25
本帖最后由 窄口牛 于 2017-8-17 12:54 编辑
- @echo off&title 各盘容量使用情况
- set m=%date:~0,4%%date:~5,2%%date:~8,2%
- >DiskCalc1.vbs echo WSCript.Echo "盘符" ^& Chr(9) ^& "总容量(GB)" ^& Chr(9) ^& "已用空间(GB)" ^& Chr(9) ^& "剩余空间(GB)" ^& Chr(9) ^& "使用率"
- >DiskCalc2.vbs echo DeviceID = Wscript.Arguments(0)
- >>DiskCalc2.vbs echo SizeAvail = Wscript.Arguments(1) / (1024 * 1024 * 1024)
- >>DiskCalc2.vbs echo SizeTotal = Wscript.Arguments(2) / (1024 * 1024 * 1024)
- >>DiskCalc2.vbs echo SizeUsed = SizeTotal - SizeAvail
- >>DiskCalc2.vbs echo SizeRate = SizeUsed / SizeTotal * 100
- >>DiskCalc2.vbs echo WSCript.Echo DeviceID ^& Chr(9) ^& Round(SizeTotal,1) ^& Chr(9) ^& Chr(9) ^& Round(SizeUsed,1) ^& Chr(9) ^& Chr(9) ^& _
- >>DiskCalc2.vbs echo Round(SizeAvail,1) ^& Chr(9) ^& Chr(9) ^& Round(SizeRate,1) ^& "%%"
- cscript //nologo DiskCalc1.vbs >>%m%.txt
- 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 (
- (for /f "tokens=1-3" %%a in ('wmic LogicalDisk where "DeviceID='%%l:'" get DeviceID ^, Size ^, FreeSpace ^| findstr ":"') do (
- cscript //nologo DiskCalc2.vbs %%a %%b %%c >>%m%.txt
- )))
- del DiskCalc*.vbs
复制代码
作者: PS2.0 时间: 2017-8-17 15:37
test.bat- @echo off
- powershell -f test.ps1 > 1.txt
复制代码
test.ps1- gwmi win32_logicaldisk -filter "drivetype = 3" | % {
- $_.deviceid + "`t" + `
- ($_.size/1GB).tostring("f2") + "`t`t" + `
- ($_.freespace/1GB).tostring("f2") + "`t`t" + `
- ($_.size/1GB-$_.freespace/1GB).tostring("f2") + "`t`t" + `
- (($_.size-$_.freespace)/$_.size*100).tostring("f2") + "%"
- }
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |