Get free disk space

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

    this works for me...

    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;
    }
    

    good luck!

提交回复
热议问题