C# を使用して、コンピューターの論理ドライブの情報にアクセスしたいと考えています。どうすればこれを達成できますか? ありがとう!
60837 次
6 に答える
76
ほとんどの情報については、 DriveInfoクラスを使用できます。
using System;
using System.IO;
class Info {
public static void Main() {
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
//There are more attributes you can use.
//Check the MSDN link for a complete example.
Console.WriteLine(drive.Name);
if (drive.IsReady) Console.WriteLine(drive.TotalSize);
}
}
}
于 2009-01-05T09:27:49.280 に答える
8
ローカル マシンで単一/特定のドライブの情報を取得する場合。DriveInfoクラスを使用して、次のように実行できます。
//C Drive Path, this is useful when you are about to find a Drive root from a Location Path.
string path = "C:\\Windows";
//Find its root directory i.e "C:\\"
string rootDir = Directory.GetDirectoryRoot(path);
//Get all information of Drive i.e C
DriveInfo driveInfo = new DriveInfo(rootDir); //you can pass Drive path here e.g DriveInfo("C:\\")
long availableFreeSpace = driveInfo.AvailableFreeSpace;
string driveFormat = driveInfo.DriveFormat;
string name = driveInfo.Name;
long totalSize = driveInfo.TotalSize;
于 2016-09-29T06:20:40.847 に答える
6
ドライブ文字がないマウントされたボリュームはどうですか?
foreach( ManagementObject volume in
new ManagementObjectSearcher("Select * from Win32_Volume" ).Get())
{
if( volume["FreeSpace"] != null )
{
Console.WriteLine("{0} = {1} out of {2}",
volume["Name"],
ulong.Parse(volume["FreeSpace"].ToString()).ToString("#,##0"),
ulong.Parse(volume["Capacity"].ToString()).ToString("#,##0"));
}
}
于 2009-09-06T05:43:01.050 に答える
5
System.IO.DriveInfo クラスを使用 http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
于 2009-01-05T09:29:28.420 に答える
3
DriveInfoクラスを調べて、必要な情報がすべて含まれているかどうかを確認します。
于 2009-01-05T09:28:19.497 に答える