■■■

2016年4月3日日曜日

論理ドライブの一覧を表示する方法

論理ドライブの一覧を表示する方法
VB.NET
ListBox1.Items.AddRange(System.Environment.GetLogicalDrives())
C#
ListBox1.Items.AddRange(System.Environment.GetLogicalDrives());
DriveInfoオブジェクトを利用してドライブ一覧を取得する方法
VB.NET
Dim drives As System.IO.DriveInfo() = System.IO.DriveInfo.GetDrives()
For Each d As System.IO.DriveInfo In drives
'"C:\"などのドライブ名を表示
Console.WriteLine(d.Name)
Next d
C#
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo d in drives)
{
//"C:\"などのドライブ名を表示
Console.WriteLine(d.Name);
}

■■■