Solved

Hard disk space

Posted on 1999-01-05
10
398 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now