이 글은 도움말을 번역한 글입니다.
Drives 컬렉션
Drives 컬렉션은 Scripting.FileSystemObject 개체를 통해 얻을 수 있는 드라이브 개체들의 컬렉션입니다. 이 컬렉션에는 시스템에 연결된 모든 드라이브(하드 드라이브, CD/DVD 드라이브, USB 드라이브 등)가 포함되어 있습니다.
Drives 컬렉션은 각 드라이브를 나타내는 Scripting.Drive 개체들로 구성되어 있으며, 각 개체는 시스템에 연결된 특정 드라이브에 대한 정보를 제공합니다. 이를 통해 드라이브의 문자, 드라이브 유형, 파일 시스템 등의 속성을 확인할 수 있습니다.
속성
Count Property
Drives 컬렉션에 있는 드라이브 개수를 반환합니다.
Sub ExampleDrivesCount()
Dim fso As Scripting.FileSystemObject
Dim drivesCollection As Scripting.Drives
' Scripting.FileSystemObject 생성
Set fso = New Scripting.FileSystemObject
' Drives 컬렉션 가져오기
Set drivesCollection = fso.Drives
' 드라이브 개수 출력
Debug.Print "드라이브 개수: " & drivesCollection.Count
' 개체 해제
Set fso = Nothing
Set drivesCollection = Nothing
End Sub
Item Property
Drives 컬렉션 내에서 특정 드라이브의 이름(문자)을 키(Key)로 사용하여 해당 드라이브 개체를 반환합니다. 이를 통해 특정 드라이브의 정보를 이름으로 찾아올 수 있습니다.
Sub ExampleDrivesItemByKey()
Dim fso As Scripting.FileSystemObject
Dim drivesCollection As Scripting.Drives
Dim drive As Scripting.drive
' Scripting.FileSystemObject 생성
Set fso = New Scripting.FileSystemObject
' Drives 컬렉션 가져오기
Set drivesCollection = fso.Drives
' C 드라이브 개체 가져오기 (드라이브 문자 "C"를 키로 사용)
Set drive = drivesCollection.Item("C")
' 드라이브 정보 출력
Debug.Print "드라이브 문자: " & drive.DriveLetter
Debug.Print "드라이브 유형: " & drive.DriveType
Debug.Print "드라이브 파일 시스템: " & drive.FileSystem
' 객체 해제
Set fso = Nothing
Set drivesCollection = Nothing
Set drive = Nothing
End Sub
비고
Drives 컬렉션에 이동식 매체 드라이브를 표시하기 위해 그 드라이브에 매체를 삽입할 필요는 없습니다.
아래 코드는 Drives 컬렉션을 가져와서 For Each...Next 문을 사용하여 그 컬렉션을 반복 실행하는 방법을 보여줍니다.
Sub ShowDriveList
Dim fs, d, dc, s, n
Set fs = CreateObject("Scripting.FileSystemObject")
Set dc = fs.Drives
For Each d in dc
s = s & d.DriveLetter & " - "
If d.DriveType = Remote Then
n = d.ShareName
Else
n = d.VolumeName
End If
s = s & n & vbCrLf
Next
MsgBox s
End Sub
메서드
Drives 컬렉션에는 메서드가 없습니다.
도움말 출처
Drives collection
Office VBA reference topic
learn.microsoft.com
'Microsoft Scripting Runtime' 카테고리의 다른 글
Folder 개체 (0) | 2023.08.10 |
---|---|
Folders 컬렉션 (0) | 2023.08.10 |
Drive 개체 (0) | 2023.08.10 |
FileSystemObject 개체 (0) | 2023.07.30 |
Dictionary (0) | 2023.07.29 |