DriveInfo Classe

Definizione

Fornisce l'accesso alle informazioni su un'unità.

public ref class DriveInfo sealed : System::Runtime::Serialization::ISerializable
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class DriveInfo : System.Runtime.Serialization.ISerializable
public sealed class DriveInfo : System.Runtime.Serialization.ISerializable
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type DriveInfo = class
    interface ISerializable
type DriveInfo = class
    interface ISerializable
Public NotInheritable Class DriveInfo
Implements ISerializable
Ereditarietà
DriveInfo
Attributi
Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrato l'uso della DriveInfo classe per visualizzare informazioni su tutte le unità nel sistema corrente.

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)
            {
                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.

Commenti

Questa classe modella un'unità e fornisce metodi e proprietà per eseguire query sulle informazioni sull'unità. Usare DriveInfo per determinare quali unità sono disponibili e quale tipo di unità sono. È anche possibile eseguire una query per determinare la capacità e lo spazio disponibile nell'unità.

Costruttori

Nome Descrizione
DriveInfo(String)

Crea una nuova istanza della DriveInfo classe .

Proprietà

Nome Descrizione
AvailableFreeSpace

Indica la quantità di spazio disponibile in un'unità, in byte.

DriveFormat

Ottiene il nome del file system, ad esempio NTFS o FAT32.

DriveType

Ottiene il tipo di unità, ad esempio CD-ROM, rimovibile, di rete o fisso.

IsReady

Ottiene un valore che indica se un'unità è pronta.

Name

Ottiene il nome di un'unità, ad esempio C:\.

RootDirectory

Ottiene la directory radice di un'unità.

TotalFreeSpace

Ottiene la quantità totale di spazio disponibile in un'unità, espressa in byte.

TotalSize

Ottiene le dimensioni totali dello spazio di archiviazione in un'unità, in byte.

VolumeLabel

Ottiene o imposta l'etichetta del volume di un'unità.

Metodi

Nome Descrizione
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetDrives()

Recupera i nomi delle unità di tutte le unità logiche in un computer.

GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce un nome di unità come stringa.

Implementazioni dell'interfaccia esplicita

Nome Descrizione
ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Popola un SerializationInfo oggetto con i dati necessari per serializzare l'oggetto di destinazione.

Si applica a