Forum: Ruby Disk Free Space

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mickael F. (Guest)
on 2006-01-23 21:59
(Received via mailing list)
Hi,

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

Mickael.
Michael F. (Guest)
on 2006-01-24 04:31
(Received via mailing list)
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>:
Timothy G. (Guest)
on 2006-01-24 19:11
(Received via mailing list)
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.
Jeffrey S. (Guest)
on 2006-01-24 19:20
(Received via mailing list)
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.
Joel VanderWerf (Guest)
on 2006-01-24 20:48
(Received via mailing list)
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.
Edwin V. (Guest)
on 2006-01-24 20:54
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
Mickael F. (Guest)
on 2006-01-28 13:55
(Received via mailing list)
I thought there would be a portable library to manage disk in general.
But thank you all for your replies.
Mickael.
This topic is locked and can not be replied to.