Get the Total Free Space on a Drive by using kernel32.dll : Windows API : Windows C# Source Code


Custom Search

C# Source Code » Windows » Windows API »

 

Get the Total Free Space on a Drive by using kernel32.dll








    
 

using System;
using System.Runtime.InteropServices;

public class GetFreeSpace {
    [DllImport("kernel32.dll", EntryPoint="GetDiskFreeSpaceExA" )]
    private static extern long GetDiskFreeSpaceEx(string lpDirectoryName, out long lpFreeBytesAvailableToCaller, out long lpTotalNumberOfBytes, out long lpTotalNumberOfFreeBytes);

    private static void Main() {
        long result, total, free, available;
        result = GetDiskFreeSpaceEx("c:", out available, out total, out free);

        if (result != 0) {
            Console.WriteLine("Total Bytes: {0:N}", total);
            Console.WriteLine("Free Bytes: {0:N}", free);
            Console.WriteLine("Available Bytes: {0:N}", available);
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Windows
» Windows API