Solved

Hard disk space

Posted on 1999-01-05
10
433 Views
Last Modified: 2008-03-06
hi,
please advise if there's any Win32 API which allows the programmer to check the hard disk space utilised/free in the codes.

thanks,
andrea
0
Comment
Question by:tanmh
  • 7
  • 2
10 Comments
 
LVL 2

Expert Comment

by:cyrilbdt
ID: 1181510
GetDiskFreeSpaceEx
0
 

Author Comment

by:tanmh
ID: 1181511
hi,
can u pls provide an example of how to call this func to get
the free disk space?

thanks.
0
 

Author Comment

by:tanmh
ID: 1181512
although the API is correct but after asking for an
example for so long, there was no answer.

other experts, would appreciate it if you can help. Basically, I don't know how to pass the parameters for the API, what's PULARGE_INTEGER?

BOOL GetDiskFreeSpaceEx(
  LPCTSTR lpDirectoryName,                
  PULARGE_INTEGER lpFreeBytesAvailableToCaller,                                                
  PULARGE_INTEGER lpTotalNumberOfBytes,    
  PULARGE_INTEGER lpTotalNumberOfFreeBytes );
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1181513
That is example of GetDiskFreeSpace:

  DWORD  lpSectorsPerCluster;      // address of sectors per cluster
  DWORD  lpBytesPerSector;      // address of bytes per sector
  DWORD  lpNumberOfFreeClusters;      // address of number of free clusters
  DWORD  lpTotalNumberOfClusters;       // address of total number of clusters
  GetDiskFreeSpace("C:\\",

    &lpSectorsPerCluster,      // address of sectors per cluster
    &lpBytesPerSector,      // address of bytes per sector
    &lpNumberOfFreeClusters,      // address of number of free clusters
    &lpTotalNumberOfClusters       // address of total number of clusters
   );
  DWORD lFree = lpNumberOfFreeClusters * lpSectorsPerCluster *
   lpBytesPerSector;
Regrds, Alex
0
 

Author Comment

by:tanmh
ID: 1181514
hi Alex,
thanks for your example.
Do u have the sample for GetDiskFreeSpaceEx instead?
or do I have to use GetDiskFreeSpace and then calculate the free disk space myself?

thanks,
Andrea
0
 

Author Comment

by:tanmh
ID: 1181515
hi Alex,

I've tried out your sample code and I got the following error:

C:\ESPdev\bin\trydatetime\main.cpp(133) : error C2664: 'GetDiskFreeSpaceW' : cannot convert parameter 1 from 'char [4]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Please advise.

Thanks, Andrea
0
 

Author Comment

by:tanmh
ID: 1181516
again after so long, no response.

would appreciate if any expert can followup and provide me with a solution.

thanks,
andrea
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 20 total points
ID: 1181517
tanmh! First reply to you  question is right(for NT)
My reply to you question is right (for Win95/31)
I post you more variant(but it makes same thing)!
If it is no work(or tanslate), you have problems
with translator!

//it is windows console apps.
#include <windows.h>
#include <iostream.h>
#include <dos.h>

void main(void)
{
  DWORD  lpSectorsPerCluster;      // address of sectors per cluster
  DWORD  lpBytesPerSector;      // address of bytes per sector
  DWORD  lpNumberOfFreeClusters;      // address of number of free clusters
  DWORD  lpTotalNumberOfClusters;       // address of total number of clusters
  GetDiskFreeSpace("C:\\",

    &lpSectorsPerCluster,      // address of sectors per cluster
    &lpBytesPerSector,      // address of bytes per sector
    &lpNumberOfFreeClusters,      // address of number of free clusters
    &lpTotalNumberOfClusters       // address of total number of clusters
   );
  long lFree = lpNumberOfFreeClusters * lpSectorsPerCluster *
                lpBytesPerSector;
  cout << lFree << endl;
//2-nd variant: _dos_getdiskfree function
   struct diskfree_t d;
   _dos_getdiskfree(3,&d);
   lFree = d.avail_clusters *     d.sectors_per_cluster*d.bytes_per_sector;
  cout << lFree << endl;
Best regards, Alex
}
0
 

Author Comment

by:tanmh
ID: 1181518
hi Alex,
Thanks for your help.
I've tried out on my VC++ v6.0 compiler.
For the 1st variant
-------------------
error C2664: 'GetDiskFreeSpaceW' : cannot convert parameter 1 from 'char [4]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

For the 2nd variant
-------------------
the compiler complained that _dos_getdiskfree(3,&d) is undeclared identifier even though i included <dos.h>

Just to check with you, for variant 1, did u set your compiler options?

Regards,
Andrea
0
 

Author Comment

by:tanmh
ID: 1181519
I've solved my problem already.
thanks.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question