DriveInfoとは? わかりやすく解説

DriveInfo クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

ドライブに関する情報へのアクセスを提供します。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 DriveInfo
    Implements ISerializable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class DriveInfo : ISerializable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class DriveInfo sealed : ISerializable
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class DriveInfo implements ISerializable
SerializableAttribute 
ComVisibleAttribute(true) 
public final class DriveInfo implements ISerializable
解説解説
使用例使用例

DriveInfo クラスを使用して現在のシステムの全ドライブに関する情報を表示する方法を次のコード例に示します。

Imports System
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("  File 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:\
'  File type: Removable
'Drive C:\
'  File 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:\
'  File 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:\
'  File type: CDRom
'
'The actual output of this code will vary based on machine and the permissions
'granted to the user executing it.
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("  File 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:\
  File type: Removable
Drive C:\
  File 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:\
  File 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:\
  File type: CDRom

The actual output of this code will vary based on machine and
 the permissions
granted to the user executing it.
*/
.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
  System.IO.DriveInfo
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DriveInfo コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

指定したドライブに関する情報へのアクセスを提供します。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    driveName As String _
)
Dim driveName As String

Dim instance As New DriveInfo(driveName)
public DriveInfo (
    string driveName
)
public:
DriveInfo (
    String^ driveName
)
public DriveInfo (
    String driveName
)
public function DriveInfo (
    driveName : String
)

パラメータ

driveName

有効なドライブ パスまたはドライブ名。大文字または小文字の 'a' ~ 'z' を使用できます。null 値は使用できません。

例外例外
例外の種類条件

ArgumentNullException

ドライブ名を null 参照 (Visual Basic では Nothing) にすることはできません。

ArgumentException

driveName の最初の文字が、大文字または小文字の 'a' ~ 'z' ではありません。

解説解説

ドライブに関する情報を取得するには、このクラスを使用します。ドライブ名は、'a' ~ 'z' の範囲の大文字または小文字にする必要があります。null 参照 (Visual Basic では Nothing) のドライブ名に関する情報の取得、または UNC (\\server\share) パスを使用するためにこのメソッドを使用することはできません。

.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DriveInfo プロパティ


DriveInfo メソッド


DriveInfo メンバ

ドライブに関する情報へのアクセスを提供します。

DriveInfo データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Runtime.Serialization.ISerializable.GetObjectData SerializationInfo オブジェクトに、オブジェクトをシリアル化するために必要なデータを設定します。
参照参照

関連項目

DriveInfo クラス
System.IO 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DriveInfo」の関連用語

DriveInfoのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DriveInfoのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS