Solved

Hard disk space

Posted on 1999-01-05
10
421 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

777 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