位置:首页 > 编程专栏 > C#

C# 获取Windows所有磁盘驱动器, 可移动硬盘, 光驱等

C# 获取Windows所有磁盘驱动器, 可移动硬盘, 光驱等
        static void Main(string[] args)
        {
            foreach (DriveInfo driver in DriveInfo.GetDrives())
            {
                if (driver.DriveType == DriveType.CDRom)
                {
                    Console.WriteLine("DVD RW 驱动器: {0}", driver.Name);
                }
                else if (driver.DriveType == DriveType.Removable)
                {
                    Console.WriteLine("可移动磁盘: {0}", driver.Name);
                }
                else if (driver.DriveType == DriveType.Fixed)
                {
                    Console.WriteLine("本地磁盘: {0}", driver.Name);
                }
                else
                {
                    Console.WriteLine("未知磁盘: {0}", driver.Name);
                }
            }

            Console.Read();
        }


C# 社区推荐