C#获取U盘或移动硬盘等设备

        using System.IO;

        /// <summary> 获取U盘或移动硬盘等设备 </summary> 
        public static List<string> Get_UsbDisk_List()
        {
            DriveInfo[] di = DriveInfo.GetDrives();//检索计算机上的所有逻辑驱动器的驱动器名称
            List<string> Div = new List<string>();
            foreach (DriveInfo d in di)
            {
                string DriveName = d.Name.ToUpper();
                if (d.DriveType == DriveType.Removable && !DriveName.Contains("A") && !DriveName.Contains("B"))
                {//获取U盘或移动硬盘等设备
                    Div.Add(d.Name);
                }
            }
            return Div;
        }

评论

  1. 60.29.28.*2019-11-18 13:14:47
    我想要获取到U盘的名字,如何获取