1. ホーム
  2. スクリプト・コラム
  3. vbs

ディスクの種類を判別し、ハードディスクの残量を検出するvbs実装コード

2022-02-08 06:54:49

コアとなるコードです。

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" 'removable drive
   Case 2 t = "Fixed" 'Hard drive
   Case 3 t = "Network" 'Network hard drive
   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 is 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