項目
ドライブの情報を取得する(FileSystemObject)
概要
FileSystemObjectを使用してドライブの情報を取得します。
例
Option Compare Database
Option Explicit
'--------------------------------------------------------
' 定数宣言領域
'--------------------------------------------------------
'DRIVE_TYPE
Private Const DRIVE_TYPE_REMOVABLE = 1
Private Const DRIVE_TYPE_FIXED = 2
Private Const DRIVE_TYPE_NETWORK = 3
Private Const DRIVE_TYPE_CDROM = 4
Private Const DRIVE_TYPE_RAMDISK = 5
'--------------------------------------------------------
' 名称 : getDriveInfo
'
' 機能 :ドライブの情報を取得する(FileSystemObject)
'
' 参照設定: Microsoft Scripting Runtime
'
'--------------------------------------------------------
Sub getDriveinfo()
Dim fso As New FileSystemObject
Dim drvPath As String
Dim drv As drive
'取得するドライブのパス
drvPath = "d:\"
On Error GoTo err_handle
Set drv = fso.GetDrive(drvPath)
With drv
Debug.Print "【"; drvPath; "の情報】"
Debug.Print
Debug.Print "合計サイズ : "; .TotalSize / 1024 / 1024; "Mバイト"
Debug.Print "空き容量 : "; .AvailableSpace / 1024 / 1024; "Mバイト"
Debug.Print "文字 : "; .DriveLetter
Debug.Print "種類 : "; getDriveType(.driveType)
Debug.Print "シリアル番号 : "; .SerialNumber
Debug.Print "ファイルシステム : "; .FileSystem
Debug.Print "仕様可? : "; .IsReady
Debug.Print "共有名 : "; .ShareName
Debug.Print "ボリューム名 : "; .VolumeName
Debug.Print "パス : "; .Path
Debug.Print "ルート フォルダ : "; .RootFolder
Debug.Print
End With
exit_handle:
Set fso = Nothing
Set drv = Nothing
Exit Sub
err_handle:
Debug.Print Err.Description
Resume exit_handle
End Sub
'--------------------------------------------------------
' getDriveType : 対応するドライブを返す
'--------------------------------------------------------
Function getDriveType(driveType)
Select Case driveType
Case DRIVE_TYPE_REMOVABLE: getDriveType = "REMOVABLE"
Case DRIVE_TYPE_FIXED: getDriveType = "FIXED"
Case DRIVE_TYPE_NETWORK: getDriveType = "NETWORK"
Case DRIVE_TYPE_CDROM: getDriveType = "CDROM"
Case DRIVE_TYPE_RAMDISK: getDriveType = "RAMDISK"
End Select
End Function