Get free disk space

前端 未结 13 1574
孤街浪徒
孤街浪徒 2020-12-02 13:04

Given each of the inputs below, I\'d like to get free space on that location. Something like

long GetFreeSpace(string path)

Inputs:

相关标签:
13条回答
  • 2020-12-02 13:39

    see this article!

    1. identify UNC par or local drive path by searching index of ":"

    2. if its is UNC PATH you cam map UNC path

    3. code to execute drive name is mapped drive name < UNC Mapped Drive or Local Drive>.

      using System.IO;
      
      private long GetTotalFreeSpace(string driveName)
      {
      foreach (DriveInfo drive in DriveInfo.GetDrives())
      {
          if (drive.IsReady && drive.Name == driveName)
          {
              return drive.TotalFreeSpace;
          }
      }
      return -1;
      }
      
    4. unmap after you requirement done.

    0 讨论(0)
提交回复
热议问题