Get free disk space

前端 未结 13 1600
孤街浪徒
孤街浪徒 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条回答
  •  猫巷女王i
    2020-12-02 13:33

    untested:

    using System;
    using System.Management;
    
    ManagementObject disk = new
    ManagementObject("win32_logicaldisk.deviceid="c:"");
    disk.Get();
    Console.WriteLine("Logical Disk Size = " + disk["Size"] + " bytes");
    Console.WriteLine("Logical Disk FreeSpace = " + disk["FreeSpace"] + "
    bytes"); 
    

    Btw what is the outcome of free diskspace on c:\temp ? you will get the space free of c:\

提交回复
热议问题