471,089 Members | 1,115 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Getting free space for a folder with a quota

1
Hello. I need to find the available space for a given path (could be a network path) with a quota applied, but when I use the following code, it gives me the available space on the entire drive. For instance, I have a drive E: that has 500 GB of available space. But I have user folders on this drive and each user has a 2 GB quota. For instance, when I use this function giving the path "E:\Users\Greg", it should return that 2 GB is free, but instead it returns 500 GB. I have verified that the quota is working in that it does not allow me to create more than 2 GB of files in that directory. Does anyone have a solution to this problem? Any help is greatly appreciated. Using C#.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using System.Runtime.ConstrainedExecution;
  5. using System.Runtime.InteropServices;
  6. using Microsoft.Win32.SafeHandles;
  7.  
  8. public class MainClass
  9. {
  10.     [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  11.     static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
  12.        out ulong lpFreeBytesAvailable,
  13.        out ulong lpTotalNumberOfBytes,
  14.        out ulong lpTotalNumberOfFreeBytes);
  15.     public static long getFreeSpace(string path)
  16.     {
  17.         ulong freeBytesAvail;
  18.         ulong totalNumOfBytes;
  19.         ulong totalNumOfFreeBytes;
  20.  
  21.         if (!GetDiskFreeSpaceEx(path, out freeBytesAvail, out totalNumOfBytes, out totalNumOfFreeBytes))
  22.         {
  23.             Console.Error.WriteLine("Error occurred: {0}",
  24.                 Marshal.GetExceptionForHR(Marshal.GetLastWin32Error()).Message);
  25.             return 0;
  26.         }
  27.         else
  28.         {
  29.             return Convert.toInt64(freeBytesAvail / (1024 * 1024));
  30.         }
  31.     }
  32. }
  33.  
Aug 19 '08 #1
1 1602
Plater
7,872 Expert 4TB
Quotas I don't think are part of the normal filesystem. You might be able to access them via a WMI call, but I don't know much more about it.
Aug 20 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Bart Simpson | last post: by
6 posts views Thread by Jim Flack | last post: by
1 post views Thread by Jody Gelowitz | last post: by
41 posts views Thread by LayneMitch via WebmasterKB.com | last post: by
185 posts views Thread by jacob navia | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.