Step 1:
Plant this code within your app or within a DLL...
public class Win32API
{
[DllImport("kernel32.dll",CharSet=CharSet.Auto)]
public static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
[MarshalAs(UnmanagedType.U8)] ref long lpFreeBytesAvailable,
[MarshalAs(UnmanagedType.U8)] ref long lpTotalNumberOfBytes,
[MarshalAs(UnmanagedType.U8)] ref long lpTotalNumberOfFreeBytes);
}
.... you will also need the following at the top of that code file...
using System.Runtime.InteropServices;
using Microsoft.Win32;
Step 2:
Make the function call from within your app...
long FreeBytesAvailable = 0;
long TotalNumberOfBytes = 0;
long TotalNumberOfFreeBytes = 0;
Win32API.GetDiskFreeSpaceEx(Path.GetPathRoot(UseADirectoryNameHere),
ref FreeBytesAvailable, ref TotalNumberOfBytes, ref
TotalNumberOfFreeBytes);
....This function will fill the three variables for you. You can then do
whatever you want with them.
HTH,
JP