# Disk Free Space

**URL:** <https://www.ruby-forum.com/t/disk-free-space/96344>\
**Category:** Ruby\
**Created:** [January 23, 2006, 8:59pm UTC](https://www.ruby-forum.com/t/disk-free-space/96344 "2006-01-23T20:59:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [January 23, 2006, 8:59pm UTC](https://www.ruby-forum.com/t/disk-free-space/96344/1 "2006-01-23T20:59:27Z")

</div>

Hi,

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

Mickael.

---

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [January 24, 2006, 3:31am UTC](https://www.ruby-forum.com/t/disk-free-space/96344/2 "2006-01-24T03:31:02Z")

</div>

for linux, it is the command df  
no idea about easy ways to do that on windows - but there sure is some  
api-call for that too…  
2006/1/24, Mickael Faivre-Macon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [January 24, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/disk-free-space/96344/3 "2006-01-24T18:11:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [January 24, 2006, 6:20pm UTC](https://www.ruby-forum.com/t/disk-free-space/96344/4 "2006-01-24T18:20:35Z")

</div>

Mickael Faivre-Macon wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [January 24, 2006, 7:48pm UTC](https://www.ruby-forum.com/t/disk-free-space/96344/5 "2006-01-24T19:48:52Z")

</div>

Jeffrey S. wrote:

> Mickael Faivre-Macon wrote:
> 
> > 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.

---

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [January 24, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/disk-free-space/96344/6 "2006-01-24T19:54:40Z")

</div>

Mickael Faivre-Macon wrote:

> 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

---

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [January 28, 2006, 12:55pm UTC](https://www.ruby-forum.com/t/disk-free-space/96344/7 "2006-01-28T12:55:25Z")

</div>

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