zoukankan      html  css  js  c++  java
  • C# -- 优先获取电脑C盘之外的磁盘来保存数据

    C# -- 优先获取电脑C盘之外的磁盘来保存数据

    1. 优先获取电脑C盘之外的磁盘来保存数据。没有其他盘则使用C盘。

    public string GetSaveDataDiskPath()
    {
        string strDiskPath = "";
    
        DriveInfo[] LocalDisks = System.IO.DriveInfo.GetDrives();
        Boolean isHaveDiskC = false;
    
        foreach (var item in LocalDisks)
        {
            if (item.Name.ToUpper() != "C:\" && item.DriveType == DriveType.Fixed && item.IsReady == true && strDiskPath == "")
            {
                strDiskPath = item.Name;
            }
            if (item.Name.ToUpper() == "C:\" && item.DriveType == DriveType.Fixed && item.IsReady == true)
            {
                isHaveDiskC = true;
            }
        }
    
        if (strDiskPath=="")
        {
            if (isHaveDiskC)
            {
                strDiskPath = "C:\";
            }
            else
            {
                throw new Exception("没有可以使用的磁盘");
            }
        }
    
        return strDiskPath;
    }
  • 相关阅读:
    网站添加背景音乐
    解决项目上的红色感叹号
    1.12那些年你不知道的爬虫面试题
    1.11you-get 视频爬取
    1.10pytesseract
    1.9Pyppeteer
    1.8request-html
    1.7XPath
    1.6Selenium XPath
    1.5cookies
  • 原文地址:https://www.cnblogs.com/ChengWenHao/p/CSharpGetPriorityDisk.html
Copyright © 2011-2022 走看看