Problems with GetDiskFreeSpaceEx/my code...
Well, after reading through posts here for a while, I decided to register :) It's really nice to have access to a board like this... Anyways, enough butt kissing!
What I want the function to do, is to check the space on each drive and print it out. Now the problem is that the total bytes information is incorrect. See the output example below.
Code:
#include <stdio.h>
#include <windows.h>
int main(void)
{
int count = 0;
ULARGE_INTEGER totalbytes, freebytes;
char drives[24][5] = {
"C:\\","D:\\","E:\\","F:\\","G:\\","H:\\","I:\\","J:\\","K:\\",
"L:\\","M:\\","N:\\","O:\\","P:\\","Q:\\","R:\\","S:\\","T:\\",
"U:\\","V:\\","W:\\","X:\\","Y:\\","Z:\\"
};
/* do a loop to check each drive */
for( count = 0 ; count<24 ; count++ )
{
/* something goes wrong, continue with next drive */
if( GetDiskFreeSpaceEx( drives[count], NULL, &totalbytes, &freebytes) == 0)
continue;
printf("\t%s\t%lu bytes free\t%lu total bytes\n",drives[count],freebytes,totalbytes);
}
return 0;
}
Code:
C:\ 1453502464 bytes free 0 total bytes
E:\ 0 bytes free 0 total bytes
As far as I can tell, the bytes free is correct (E:\ is a CD drive). But the total bytes won't show the correct value. It's supposed to display around 6 gigs for the C drive and 83 MB for the E drive. Thanks in advance for any help :)
scrappy
Re: Problems with GetDiskFreeSpaceEx/my code...
Code:
#include <stdio.h>
#include <windows.h>
int main(void)
{
int count = 0;
ULARGE_INTEGER totalbytes, freebytes;
char drives[24][5] = {
"C:\\","D:\\","E:\\","F:\\","G:\\","H:\\","I:\\","J:\\","K:\\",
"L:\\","M:\\","N:\\","O:\\","P:\\","Q:\\","R:\\","S:\\","T:\\",
"U:\\","V:\\","W:\\","X:\\","Y:\\","Z:\\"
};
/* do a loop to check each drive */
for( count = 0 ; count<24 ; count++ )
{
/* something goes wrong, continue with next drive */
if( GetDiskFreeSpaceEx( drives[count], NULL, &totalbytes, &freebytes) == 0)
continue;
printf("\t%s\t%0.0f bytes free\t%0.0f total bytes\n",
drives[count],(double)(__int64)freebytes.QuadPart ,(double)(__int64)totalbytes.QuadPart );
}
return 0;
}
Code:
C:\ 1450516480 bytes free 6465036288 total bytes
E:\ 0 bytes free 84213760 total bytes
I did some searching around and found a way to alter the printf statement. Now it shows the correct values. I'm not sure if it's correct, but it works (so it must be correct). Thanks Salem for the link also. Good stuff to know.
scrappy