Cross-platform way to list all drives/volumes/mount-points?

Hey all,

I’m looking for a way to reliably list all drive letters or volume names
or mount points on a system.

Google has not helped me. Best I could find was
java.io.File.listRoots(), but on my Linux box it simply gives ‘/’ as the
sole root name, despite other devices being mounted.

Ultimately I want to check free disk space. The Apache project’s
org.apache.commons.io.FileSystemUtils has freeSpaceKb, but it needs to
be told the path to check.

Is there some Java/JRuby/Ruby way to do this across Win32, *nix, and
OSX? Pretty please? :slight_smile:

Worst case, I fall back to platform detection and some use of regexen
and shell commands. But I thought perhaps someone has blazed this path
already.

Thanks,

James

Neurogami - Smart application development

[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

James B. wrote:

org.apache.commons.io.FileSystemUtils has freeSpaceKb, but it needs to
be told the path to check.

Is there some Java/JRuby/Ruby way to do this across Win32, *nix, and
OSX? Pretty please? :slight_smile:

Worst case, I fall back to platform detection and some use of regexen
and shell commands. But I thought perhaps someone has blazed this path
already.

That’s the only thing that comes to mind…searching fstab or running
“mount” and so on. Maybe ask on ruby-talk and see if someone there has
an idea?

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. wrote:

James B. wrote:

Worst case, I fall back to platform detection and some use of regexen
and shell commands. But I thought perhaps someone has blazed this
path already.

That’s the only thing that comes to mind…searching fstab or running
“mount” and so on. Maybe ask on ruby-talk and see if someone there has
an idea?

I may do that. Best I saw was a sysutils gem, but it uses native code.

So far, I’ve written some methods that grab the results of df and grab
the names of things mounted off /dev/*

Seems OK, if you don’t stare directly at it.

James

Neurogami - Smart application development

[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Trejkaz wrote:

I wonder if NIO2 is going to give us this API. It would be nice.

Probably a good chance. I wonder how much of it is in the dev builds of
Java 7?

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. wrote:

That doesn’t sound very cross-platform. What about our poor friends
saddled with that W-word OS? :slight_smile:

I wonder if NIO2 is going to give us this API. It would be nice.

Probably a good chance. I wonder how much of it is in the dev builds of
Java 7?

Here’s what I ended up doing:

Check the CONFIG[‘target_os’]. If not mswin32, call df and parse the
text.

Else, call

  java.io.File.list_roots.map{ |r| r.path }

I then used

org.apache.commons.io.FileSystemUtils.freeSpace path

to get the free space (which, as it seems, shells out to assorted
platform-specific commands, such as ‘df’. :slight_smile: )

James

Neurogami - Smart application development

[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. wrote:

Sounds like a good gem :slight_smile:

What? really-hacky-free-space-0.0.1.gem?

It feels really fragile.

Maybe a gist would work better. :slight_smile:

James

Neurogami - Smart application development

[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Tue, Jun 9, 2009 at 5:30 PM, James B.[email protected] wrote:

 org.apache.commons.io.FileSystemUtils.freeSpace path

to get the free space (which, as it seems, shells out to assorted
platform-specific commands, such as ‘df’. :slight_smile: )

Sounds like a good gem :slight_smile:

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email