-
November 23rd, 2014, 07:22 AM
#1
Getting Free Disk Space of certain directory
Code:
_int64 free_space_64bit;
PULARGE_INTEGER lpFreeBytesAvailable, lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes;
//char currentPath[MAX_PATH];
//GetCurrentDirectoryA(MAX_PATH, currentPath);
GetDiskFreeSpaceExA("H:\\C", lpFreeBytesAvailable, lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes);
free_space_64bit = lpFreeBytesAvailable->HighPart << 32 | lpFreeBytesAvailable->LowPart;
This directory "H:\\C" does exist, if I comment out the GetDiskFreeSpaceExA line, the program doesn't crash, but it leads to some peculiar results (some uninitialized and random value, but at least it doesn't crash)
Any ideas?
Thanks
Jack
Last edited by lucky6969b; November 23rd, 2014 at 07:28 AM.
-
November 23rd, 2014, 07:36 AM
#2
Re: Getting Free Disk Space of certain directory
Still not working
Code:
LPDWORD lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters;
//char currentPath[MAX_PATH];
//GetCurrentDirectoryA(MAX_PATH, currentPath);
GetDiskFreeSpaceA("H:\\C",lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters);
free_space_64bit = *lpBytesPerSector * *lpSectorsPerCluster * *lpNumberOfFreeClusters;
-
November 23rd, 2014, 08:20 AM
#3
Re: Getting Free Disk Space of certain directory
The pointers you're passing as arguments aren't initialized.
-
November 23rd, 2014, 09:16 AM
#4
Re: Getting Free Disk Space of certain directory
Code:
DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters;
GetDiskFreeSpaceA("H:\\C",&SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
free_space_64bit = BytesPerSector * SectorsPerCluster * NumberOfFreeClusters;
You need to pass the address of the variables used. GetDiskFreeSpaceEx() is used similarly.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 23rd, 2014, 09:36 PM
#5
Re: Getting Free Disk Space of certain directory
-
November 24th, 2014, 04:32 AM
#6
Re: Getting Free Disk Space of certain directory
But one thing, is that how come this api would tell that a "directory" has 3Gigs but the total disk space for the drive is 20Gigs up
What is the true meaning of the free disk space of a "directory"?
Thanks
Jack
-
November 24th, 2014, 05:43 AM
#7
Re: Getting Free Disk Space of certain directory
There's such a thing called quota. Physical disk free space is a physical limit, but user's quota is a virtual one.
Last edited by Igor Vartanov; November 24th, 2014 at 02:47 PM.
Best regards,
Igor
-
November 24th, 2014, 05:49 AM
#8
Re: Getting Free Disk Space of certain directory
Besides quota there might be another sort of limit, not that obvious one. In case the directory is a symlink pointing to a directory hosted on other physical drive, the real directory limit is the corresponding drive free space.
Best regards,
Igor
-
November 24th, 2014, 08:01 AM
#9
Re: Getting Free Disk Space of certain directory
hence... if you want the free space on the volume, you should query the free space for the root path.
Anything else might be more/less than that depending on what the path really is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|