虎牙客服投诉电话多少:一个关于 System.IO.Directory 的问题

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 03:31:53
Directory.GetLogicalDrives() 可以得到本地磁盘,同时包括软区和光区,事实上我只想要C,D,E,F硬盘,请问如何排除掉软区和光区,谢谢!!

using System;
using System.IO;
using System.Runtime.InteropServices;
namespace ConsoleApplicationBaidu
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
[DllImport("kernel32.dll", EntryPoint="GetDriveTypeA")]
public static extern int GetDriveTypeA (string nDriver);
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{//Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
string []d=Directory.GetLogicalDrives();
foreach(string tmp in d)
{

Console.Write(tmp);
int dt=GetDriveTypeA(tmp);
switch(dt)
{
case 3:
{
Console.WriteLine("是硬盘分区!");
break;
}
case 5:
{
Console.WriteLine("是光盘!");
break;
}

}
/* DRIVE_UNKNOWN The drive type cannot be determined.
DRIVE_NO_ROOT_DIR The root path is invalid. For example, no volume is mounted at the path.
DRIVE_REMOVABLE The disk can be removed from the drive.
DRIVE_FIXED The disk cannot be removed from the drive.
DRIVE_REMOTE The drive is a remote (network) drive.
DRIVE_CDROM The drive is a CD-ROM drive.
DRIVE_RAMDISK The drive is a RAM disk. */

}
}
}
}