Thread: Problems with GetDiskFreeSpaceEx/my code...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    85

    Question 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

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    85

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with compiling code in cygwin
    By firyace in forum C++ Programming
    Replies: 4
    Last Post: 06-01-2007, 08:16 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 01:30 PM
  3. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM
  4. structs, array, code has problems, Im lost
    By rake in forum C++ Programming
    Replies: 4
    Last Post: 03-13-2002, 02:02 AM
  5. problems with output from code
    By simhap in forum C++ Programming
    Replies: 0
    Last Post: 10-08-2001, 12:43 PM