Solved

Hard disk space

Posted on 1999-01-05
10
428 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lambda for random numbers problem 7 116
Grammars for C C++ and java 1 131
C++ error cannot convert from std::string to const char * 6 243
Arduino EDI - Programming language 3 103
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

807 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