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.
2f6686bd2c6bb633a1cbf7b5a73c8491?d=identicon&s=25 Mickael Faivre-Macon (micktaiwan)
on 2006-01-23 20: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.
86e33dee4a89a8879a26487051c216a8?d=identicon&s=25 Michael Fellinger (Guest)
on 2006-01-24 03: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 <faivrem@gmail.com>:
Be223e60c56535a0e465b84243aeb0d1?d=identicon&s=25 Timothy Goddard (Guest)
on 2006-01-24 18: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.
149379873fe2cb70e550c6bff8fedd0c?d=identicon&s=25 Jeffrey Schwab (Guest)
on 2006-01-24 18: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.
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2006-01-24 19:48
(Received via mailing list)
Jeffrey Schwab 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.
784481e009179262d133db1f1eb3bfb1?d=identicon&s=25 Edwin Van leeuwen (blackedder)
on 2006-01-24 19: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
2f6686bd2c6bb633a1cbf7b5a73c8491?d=identicon&s=25 Mickael Faivre-Macon (micktaiwan)
on 2006-01-28 12: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.