473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1702
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

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

Similar topics

1
by: Bart Simpson | last post by:
Hi, I'm testing to control Windows disk quota by PythonWin on win2003 and winXP. But ther is some problem.. This is the test code: import win32com.client
3
by: Jas Shultz | last post by:
I'm using Win2K3 Enterprise edition with the latest .NET framework installed. I have this problem with getting "out of disk space" errors. It doesn't happen all the time but it does happen. When...
6
by: Jim Flack | last post by:
I have a new website hosted by www.easily.co.uk which contains a mysql database (I have the initial access codes etc ). My problem is I have never used PHP or dealt with mysql before. I have tried...
1
by: Jody Gelowitz | last post by:
Exactly what is the size limit of Isolated Storage in the Internet permission set? I have a document indicating it is 10MB (http://msdn.microsoft.com/msdnmag/issues/02/07/NetSmartClients/) ...
7
by: gemel | last post by:
I am developing an application that uses SQL 2000 as my source of images. I have successfully created the code to load the images onto the SQL Server and also to retrieve the images into a dataset....
4
by: Sean Shanny | last post by:
To all, Running into an out of memory error on our data warehouse server. This occurs only with our data from the 'September' section of a large fact table. The exact same query running over...
41
by: LayneMitch via WebmasterKB.com | last post by:
I was just chating with a few webdevelopers and it was brought to my attention that I need some type of server technology installed on my computer so I could get a visual of how my sites would look...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
6
by: Author | last post by:
I have VS 2005 professional. Here is the version info: Microsoft Visual Studio 2005 Version 8.0.50727.762 (SP .050727-7600) © 2005 Microsoft Corporation. All rights reserved. When I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.