Disk_free_space

Hi,

I need an equivalent of $subj php function in ruby… I have a directory
and I need to find out how much I can save there… Only idea I have is
to find mountpoint and then parse /proc, but it’s very ugly solution :slight_smile:

Thank you for help.

Darken wrote:

I need an equivalent of $subj php function in ruby… I have a directory
and I need to find out how much I can save there… Only idea I have is
to find mountpoint and then parse /proc, but it’s very ugly solution :slight_smile:

You can do this simply if not truly portably like so:

class << self
define_method :disk_free_space, &begin
require ‘Win32API’
df = Win32API.new(“kernel32”, “GetDiskFreeSpaceEx”, “pppp”, “i”)
proc do |dir|
df.call(dir, ret=" ", " ", " ")
ret.unpack(“L”)[0]
end
rescue LoadError
proc do |dir|
df -k #{dir}[/\S+\s+\S+\s+\S+\s+(\d+)/, 1].to_i * 1024
end
end
end

Obviously if your df -k foo gives you output in a different format,
you’ll need to change the regular expression. (The way I’ve written it,
it’s looking for available space in 1k blocks in the fourth column.)

Cheers,
Dave

Thank you… parsing df output is working fine… anyway,it will be nice
to have more… ruby… solution.

On Jun 22, 2006, at 11:03 AM, Darken wrote:

Thank you… parsing df output is working fine… anyway,it will be
nice
to have more… ruby… solution.

I googled around out of curiosity and it looks like there used to be
something called “filesystem” by Mike Hall. But it’s no longer
available. Anyone on the list know what happened to it?
-Mat

I was googling and searching newsgroups archive before I asked, can you
help me a bit please?

Darken wrote:

Hi,

I need an equivalent of $subj php function in ruby… I have a directory
and I need to find out how much I can save there… Only idea I have is
to find mountpoint and then parse /proc, but it’s very ugly solution :slight_smile:

There was a thread here on ruby-talk not long ago on this very topic.

Search the archives.


James B.

“People want simple stories.”

Austin wrote:

Remember that the newsgroups comp.lang.ruby has been disconnected due
to circumstances beyond control.

I dare say there are those whose control it is not beyond. God, for
example, Matz, if he had a reason, or even possibly James Edward G.
II who said a week or two ago that he might have a new gateway server
in the works.

Cheers,
Dave

On 6/22/06, Dave B. [email protected] wrote:

Austin wrote:

Remember that the newsgroups comp.lang.ruby has been disconnected due
to circumstances beyond control.
I dare say there are those whose control it is not beyond. God, for
example, Matz, if he had a reason, or even possibly James Edward G.
II who said a week or two ago that he might have a new gateway server
in the works.

Unfortunately, it isn’t necessarily controllable, even for Matz or
James. It is, in part, dependent upon a service provider’s
willingness. The original gateway went down because the host of the
gateway changed from service provider A to service provider B. When
signing up with provider B, they gateway host had discussed with them
the possibility of doing mailing-list/newsgroup gateway and had been
assured that it would be okay. When the switch was done, however,
provider B reneged on this.

With increasing numbers of hosting providers dropping support for
Usenet, what makes you think that it would be “easy” to manage this?

-austin

On 6/22/06, Darken [email protected] wrote:

I was googling and searching newsgroups archive before I asked, can you
help me a bit please?

Start from here:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/193509

Remember that the newsgroups comp.lang.ruby has been disconnected due
to circumstances beyond control.

-austin

Austin Z. wrote:

On 6/22/06, Dave B. [email protected] wrote:

I dare say there are those whose control it is not beyond.
With increasing numbers of hosting providers dropping support for
Usenet, what makes you think that it would be “easy” to manage this?

I never said the word “easy,” nor did I intend to imply anything more
than that it can be done. But does no word from James mean that
possibility’s fallen through?

Cheers,
Dave

On 6/25/06, Dave B. [email protected] wrote:

Austin Z. wrote:

On 6/22/06, Dave B. [email protected] wrote:

I dare say there are those whose control it is not beyond.
With increasing numbers of hosting providers dropping support for
Usenet, what makes you think that it would be “easy” to manage this?
I never said the word “easy,” nor did I intend to imply anything more
than that it can be done. But does no word from James mean that
possibility’s fallen through?

Don’t know. We’d have to ask them. But it may not be within James’s
control at this point.

-austin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs