Disk Free Space

  • Thread starter Mickael Faivre-Macon
  • Start date
M

Mickael Faivre-Macon

Hi,

Is a way to know free disk space left other that using Win32 API or a
system call on linux ?

Mickael.
 
M

Michael Fellinger

Zm9yIGxpbnV4LCBpdCBpcyB0aGUgY29tbWFuZCBkZgpubyBpZGVhIGFib3V0IGVhc3kgd2F5cyB0
byBkbyB0aGF0IG9uIHdpbmRvd3MgLSBidXQgdGhlcmUgc3VyZSBpcyBzb21lCmFwaS1jYWxsIGZv
ciB0aGF0IHRvby4uLgoyMDA2LzEvMjQsIE1pY2thZWwgRmFpdnJlLU1hY29uIDxmYWl2cmVtQGdt
YWlsLmNvbT46Cj4gSGksCj4KPiBJcyBhIHdheSB0byBrbm93IGZyZWUgZGlzayBzcGFjZSBsZWZ0
IG90aGVyIHRoYXQgdXNpbmcgV2luMzIgQVBJIG9yIGEKPiBzeXN0ZW0gY2FsbCBvbiBsaW51eCA/
Cj4KPiBNaWNrYWVsLgo+Cj4K
 
T

Timothy Goddard

This is highly OS-specific so I sincerely doubt there is a general
method. Different OSes treat disks entirely differently. To demonstrate
the complexity, simply ask yourself these questions: Is a network share
a disk? A folder on a remote FTP server? A loop device mounting a file
on a remote SMB server accessed via a VPN? The file itself?

Try either using a system-specific call for each platform you may be
operating on or simply try to write your stuff to the disk, catching
the appropriate error if it fails.
 
J

Joel VanderWerf

Jeffrey said:
Mickael said:
Is a way to know free disk space left other that using Win32 API or a
system call on linux ?

On {U,Li}n[iu]x, df.
On Windows, dir. It's the last line of output.

You can install the GnuWin32 tools on windows to get df working there, IIRC.
 
E

Edwin van Leeuwen

Mickael said:
Hi,

Is a way to know free disk space left other that using Win32 API or a
system call on linux ?

Mickael.

A way to directly make the correct system call from ruby:
size = 64
unpack_fmt = 'iiiiiiiiiiiiiiii'
foo = ' ' * size
syscall(99, "/mountpoint", foo)
type, @bsize, @blocks, @bfree, @bavail, @files, @ffree, tmp,tmp,@namelen
= foo.unpack(unpack_fmt)
usage=100*(@blocks-@bfree)/@blocks

(Copied from someone who wrote a ruby script that did the same thing as
df.)

Edwin
 
M

Mickael Faivre-Macon

I thought there would be a portable library to manage disk in general.
But thank you all for your replies.
Mickael.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top