Get free disk space

前端 未结 13 1598
孤街浪徒
孤街浪徒 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:26

    I was looking for the size in GB, so I just improved the code from Superman above with the following changes:

    public double GetTotalHDDSize(string driveName)
    {
        foreach (DriveInfo drive in DriveInfo.GetDrives())
        {
            if (drive.IsReady && drive.Name == driveName)
            {
                return drive.TotalSize / (1024 * 1024 * 1024);
            }
        }
        return -1;
    }
    

提交回复
热议问题