• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Retrieve list of drives in Win and Mac OSX

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a small PC Java application that I am 'quickly' porting to Mac OS X. To get the list of drives, it's currently using:

File.listRoots()

I got it working calling:

File.listRoots()[0].listFiles((java.io.FilenameFilter) new NameFileFilter("Volumes"))[0].listFiles()

but I don't really like it and just wonder if there's a cleaner way to deal with drives in multi-platform environment.

Looks like a quite common problem but I can't find a reasonable solution. Unfortunately I can't change to much the windows code...

Am I looking in the wrong direction?

Renato
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mac OS X, like all UNIX-based systems, doesn't really have the clear-cut notion of "drives" the way that Windows does; there's a single file system within which various physical drives are mounted. Your "Volumes" list is really the only way to get this information from Java.

I'm going to move this to our Mac OS X forum, just in case there's a platform-specific trick I don't know about.
[ May 12, 2006: Message edited by: Ernest Friedman-Hill ]
 
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EFH is correct; there really isn't any concept of physical drives the way that there is in Windows. UNIX systems abstract the concept to volumes.

The content of the /Volumes "folder" is about as close as you are going to get to a similar concept. But be aware that mounted DVDs, CDs, USB "thumb drives", external firewire/USB2 drives, and even mounted disk images will also appear in this folder. It can even (usually created by accident) have hard-drive folders in it.
 
Renato Losio
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your feedback!

Cheers,

Renato
reply
    Bookmark Topic Watch Topic
  • New Topic