DriveInfo 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供對磁碟上資訊的存取。
public ref class DriveInfo sealed : System::Runtime::Serialization::ISerializable
public ref class DriveInfo sealed
public sealed class DriveInfo : System.Runtime.Serialization.ISerializable
public sealed class DriveInfo
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class DriveInfo : System.Runtime.Serialization.ISerializable
type DriveInfo = class
interface ISerializable
type DriveInfo = class
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type DriveInfo = class
interface ISerializable
Public NotInheritable Class DriveInfo
Implements ISerializable
Public NotInheritable Class DriveInfo
- 繼承
-
DriveInfo
- 屬性
- 實作
範例
下列程式代碼範例示範如何使用 DriveInfo 類別來顯示目前系統上所有磁碟驅動器的相關信息。
using System;
using System.IO;
class Test
{
public static void Main()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" Drive type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(
" Available space to current user:{0, 15} bytes",
d.AvailableFreeSpace);
Console.WriteLine(
" Total available space: {0, 15} bytes",
d.TotalFreeSpace);
Console.WriteLine(
" Total size of drive: {0, 15} bytes ",
d.TotalSize);
}
}
}
}
/*
This code produces output similar to the following:
Drive A:\
Drive type: Removable
Drive C:\
Drive type: Fixed
Volume label:
File system: FAT32
Available space to current user: 4770430976 bytes
Total available space: 4770430976 bytes
Total size of drive: 10731683840 bytes
Drive D:\
Drive type: Fixed
Volume label:
File system: NTFS
Available space to current user: 15114977280 bytes
Total available space: 15114977280 bytes
Total size of drive: 25958948864 bytes
Drive E:\
Drive type: CDRom
The actual output of this code will vary based on machine and the permissions
granted to the user executing it.
*/
Imports System.IO
Class Test
Public Shared Sub Main()
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim d As DriveInfo
For Each d In allDrives
Console.WriteLine("Drive {0}", d.Name)
Console.WriteLine(" Drive type: {0}", d.DriveType)
If d.IsReady = True Then
Console.WriteLine(" Volume label: {0}", d.VolumeLabel)
Console.WriteLine(" File system: {0}", d.DriveFormat)
Console.WriteLine( _
" Available space to current user:{0, 15} bytes", _
d.AvailableFreeSpace)
Console.WriteLine( _
" Total available space: {0, 15} bytes", _
d.TotalFreeSpace)
Console.WriteLine( _
" Total size of drive: {0, 15} bytes ", _
d.TotalSize)
End If
Next
End Sub
End Class
'This code produces output similar to the following:
'
'Drive A:\
' Drive type: Removable
'Drive C:\
' Drive type: Fixed
' Volume label:
' File system: FAT32
' Available space to current user: 4770430976 bytes
' Total available space: 4770430976 bytes
' Total size of drive: 10731683840 bytes
'Drive D:\
' Drive type: Fixed
' Volume label:
' File system: NTFS
' Available space to current user: 15114977280 bytes
' Total available space: 15114977280 bytes
' Total size of drive: 25958948864 bytes
'Drive E:\
' Drive type: CDRom
'
'The actual output of this code will vary based on machine and the permissions
'granted to the user executing it.
備註
此類別會建立磁碟驅動器的模型,並提供方法來查詢磁碟驅動器資訊。 使用 DriveInfo 來判斷可用的磁碟驅動器,以及磁碟驅動器的類型。 您也可以查詢以判斷磁碟驅動器上的容量和可用空間。
建構函式
DriveInfo(String) |
建立 DriveInfo 類別的新執行個體。 |
屬性
AvailableFreeSpace |
表示磁碟機上的可用空間量,以位元組為單位。 |
DriveFormat |
取得檔案系統的名稱,例如 NTFS 或 FAT32。 |
DriveType |
取得磁碟類型,例如 CD-ROM、卸除式、網路或固定式。 |
IsReady |
取得值,這個值表示磁碟機是否已就緒。 |
Name |
取得磁碟機名稱,例如 C:\。 |
RootDirectory |
取得磁碟的根目錄。 |
TotalFreeSpace |
取得磁碟機上可用空間的總量,以位元組為單位。 |
TotalSize |
取得磁碟機上儲存空間的總大小,以位元組為單位。 |
VolumeLabel |
取得或設定磁碟的磁碟區標籤。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetDrives() |
擷取電腦上所有邏輯磁碟的磁碟名稱。 |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
將磁碟名稱以字串方式傳回。 |
明確介面實作
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
在 SerializationInfo 物件中填入序列化目標物件所需的資料。 |