Disk space exception ?

S

Sagar Choudhary

Is there any exception related to disk space ?
If not how else can we check the availability of the disk space in a
c++ program. I know ostream helps a bit. When we try to open a file
when there's no disk space ostream::rdstate() returns badbit.
 
P

Peter MacMillan

Sagar said:
Is there any exception related to disk space ?
If not how else can we check the availability of the disk space in a
c++ program. I know ostream helps a bit. When we try to open a file
when there's no disk space ostream::rdstate() returns badbit.

IIRC, that's a platform specific thing that you'll want to look into the
platform documentation for. I'm not aware of any standard C++ way of
finding how much space is free (apart from the ostream being writable
and it... not being writable or, as you pointed out, returning an error).

For example, the Microsoft Windows PlatformSDK offers:

BOOL GetDiskFreeSpace(
LPCTSTR lpRootPathName,
LPDWORD lpSectorsPerCluster,
LPDWORD lpBytesPerSector,
LPDWORD lpNumberOfFreeClusters,
LPDWORD lpTotalNumberOfClusters
);

(include windows.h)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getdiskfreespace.asp




--
Peter MacMillan
e-mail/msn: (e-mail address removed)
icq: 1-874-927

GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$
N o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r--
y(--)
 
T

Thomas Matthews

Sagar said:
Is there any exception related to disk space ?
If not how else can we check the availability of the disk space in a
c++ program. I know ostream helps a bit. When we try to open a file
when there's no disk space ostream::rdstate() returns badbit.
Wrong, or let us clarify. The rdstate() method returns
badbit when there is problem writing to the stream. We
don't have a clue as to which problem(s) are associated
with the "badbit". For example, one could not distinguish
faulty media, missing media or full media by using the
"badbit". All we know is that there was an error. The
details are up to the implementation or the platform.

As for availability of disk space, the best course of
action is to use some platform specific functions since
C++ has no support for this.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top