private GetDiskFreeSpaceEx ( string lpDirectoryName, ulong &lpFreeBytesAvailable, ulong &lpTotalNumberOfBytes, ulong &lpTotalNumberOfFreeBytes ) : bool | ||
lpDirectoryName | string | |
lpFreeBytesAvailable | ulong | |
lpTotalNumberOfBytes | ulong | |
lpTotalNumberOfFreeBytes | ulong | |
return | bool |
/// <summary> /// Return the number of available bytes in the specified file path. /// </summary> /// <remarks> /// DriveInfo.AvailableFreeSpace gives this information, but only for drives. This makes it less useful /// as paths may contain NTFS junction points, symbolic links, or be UNC paths. /// </remarks> /// <param name="path">The standard or UNC path to retrieve available bytes for.</param> /// <returns>The number of free bytes available to the current user in the specified location.</returns> internal static ulong PathAvailableSpace(string path) { if (Windows()) { ulong freeBytesAvailable, totalAvailableBytes, totalFreeBytes; if (!NativeMethods.GetDiskFreeSpaceEx(path, out freeBytesAvailable, out totalAvailableBytes, out totalFreeBytes)) { throw new Win32Exception(); } return(freeBytesAvailable); } else { // Call the private Mono internal method System.IO.DriveInfo.GetDiskFreeSpace // as this does exactly the same as GetDiskFreeSpaceEx does under Windows MethodInfo dynMethod = typeof(DriveInfo).GetMethod("GetDiskFreeSpace", BindingFlags.NonPublic | BindingFlags.Static); object[] args = new object[] { path, null, null, null }; dynMethod.Invoke(null, args); return((ulong)args[3]); } }
/// <summary> /// Return the number of available bytes in the specified file path. /// </summary> /// <remarks> /// DriveInfo.AvailableFreeSpace gives this information, but only for drives. This makes it less useful /// as paths may contain NTFS junction points, symbolic links, or be UNC paths. /// </remarks> /// <param name="path">The standard or UNC path to retrieve available bytes for.</param> /// <returns>The number of free bytes available to the current user in the specified location.</returns> internal static ulong PathAvailableSpace(string path) { ulong freeBytesAvailable, totalAvailableBytes, totalFreeBytes; if (!NativeMethods.GetDiskFreeSpaceEx(path, out freeBytesAvailable, out totalAvailableBytes, out totalFreeBytes)) { throw new Win32Exception(); } return(freeBytesAvailable); }