Results 1 to 7 of 7

Thread: GetDiskFreeSpace

  1. #1

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471

    GetDiskFreeSpace

    Can someone help me out with the GetDiskFreeSpace API?

    Here is what i have and i'm getting values that don't seem correct.

    Code:
    unsigned long *lpSectorsPerCluster;
    	unsigned long *lpBytesPerSector;
    	unsigned long *lpNumberOfFreeClusters;
    	unsigned long *lpTotalNumberOfClusters;
    	
    	GetDiskFreeSpace("C:", lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters);
    	cout << ((*lpTotalNumberOfClusters / 100) * (*lpSectorsPerCluster / 100) * (*lpBytesPerSector / 100))<< " Bytes Total" << endl;
    	cout << ((*lpNumberOfFreeClusters / 100) * (*lpSectorsPerCluster / 100) * (*lpBytesPerSector / 100)) << " Bytes Free" << endl;
    thx in advance for any help
    Bababooey
    Tatatoothy
    Mamamonkey

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Re: GetDiskFreeSpace

    Originally posted by noble
    Can someone help me out with the GetDiskFreeSpace API?

    Here is what i have and i'm getting values that don't seem correct.

    Code:
    unsigned long lpSectorsPerCluster;
    	unsigned long lpBytesPerSector;
    	unsigned long lpNumberOfFreeClusters;
    	unsigned long lpTotalNumberOfClusters;
    	
    	GetDiskFreeSpace("C:", &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters, &lpTotalNumberOfClusters);
    	cout << ((*lpTotalNumberOfClusters / 100) * (*lpSectorsPerCluster / 100) * (*lpBytesPerSector / 100))<< " Bytes Total" << endl;
    	cout << ((*lpNumberOfFreeClusters / 100) * (*lpSectorsPerCluster / 100) * (*lpBytesPerSector / 100)) << " Bytes Free" << endl;
    The idea is that you pass a pointer to your variables, not pass the VALUE from a pointer variable you have...see my subtle changes in the variable declaration...

    Argh gotta go...change the printing to avoid the dereference...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    still seem off by a little.....

    Code:
    unsigned long lpSectorsPerCluster;
    		unsigned long lpBytesPerSector;
    		unsigned long lpNumberOfFreeClusters;
    		unsigned long lpTotalNumberOfClusters;
    		
    		GetDiskFreeSpace(szDriveLetter, &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters, &lpTotalNumberOfClusters);
    		cout << ((lpTotalNumberOfClusters / 100) * (lpSectorsPerCluster / 100) * (lpBytesPerSector / 100)) << " Bytes Total" << endl;
    		cout << ((lpNumberOfFreeClusters / 100) * (lpSectorsPerCluster / 100) * (lpBytesPerSector / 100)) << " Bytes Free" << endl;
    Bababooey
    Tatatoothy
    Mamamonkey

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    GetDiskFreeSpaceEx will be simpler to use. It was designed to replace GetDiskFreeSpace.

    But if you want to use GetDiskFreeSpace, why do you divide all numbers by 100?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    oops, i copied some code from a previous project and forgot
    to take out the dividing by 100. Still doesn't give me a correct
    reading on the free space....

    I'm not using GetDiskFreeSpaceEx because I need to know the
    sectors and such.

    Thanks again
    Bababooey
    Tatatoothy
    Mamamonkey

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Noble, I just said it was off - I'd written the core part of the reply before I got dragged off to do my presentation (on a course at the moment).

    If you didn't notice the fact that I said you needed to follow the changes in the variables through to remove the dereferencing

    Anyway, have you tried looking up GetDiskSpaceFree on MSDN?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    thx parksie for your help, i realized what I did wrong before and
    fixed it
    Bababooey
    Tatatoothy
    Mamamonkey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width