欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vbs判断磁盘类型和检测硬盘剩余空间的实现代码

程序员文章站 2022-03-07 15:27:48
核心代码: function showdrivetype(drvpath) dim fso, d, t set fso = createobject(...

核心代码:

function showdrivetype(drvpath)
  dim fso, d, t
  set fso = createobject("scripting.filesystemobject")
  set d = fso.getdrive(fso.getdrivename(drvpath))
  select case d.drivetype
   case 0 t = "unknown"
   case 1 t = "removable"  '移动硬盘
   case 2 t = "fixed"    '硬盘
   case 3 t = "network"   '网络硬盘
   case 4 t = "cd-rom"
   case 5 t = "ram disk"   'ram
  end select
  showdrivetype = "drive " & d.driveletter & ": - " & t
end function
 
function showfreespace(drvpath) 
 dim fso, d, s
 set fso = createobject("scripting.filesystemobject")
 set d = fso.getdrive(fso.getdrivename(drvpath))    'd为f:
 s = "drive " & ucase(drvpath) & " - "
 s = s & d.volumename & " "
 s = s & "free space: " & formatnumber(d.freespace/1024, 0)
 s = s & " kbytes"
 showfreespace = s
end function
 
dim message
 
message = showdrivetype("f:\programming\applications")
msgbox message
message = showfreespace("f:\programming\applications")
msgbox message