Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Identify Local Hard Drives Only  RSS feed

 
Kevin Brennan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there an algorithm to query the system and identify only local hard drives (not network shares nor removable media)? So far, everything I tried to test for this causes a windoes message box asking me to mount media in the removable drive. I want to ignore such drives in my process and not have this message occur. This also needs to run on a Mac.

Thanks.
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tried it myself but the FileSystemView class seems to offer methods for this.

FileSytemView in javadocs

The following methods seem to be interesting for you!

public boolean isDrive(File dir)
public String getSystemTypeDescription(File f)
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The methods in FileSystemView look promising, but it's an abstract class in which many of the methods have only nominal implementation (presumably to make extension more manageable).

For example, the methods isDrive and isFloppyDrive always return false, since "the default implementation has no way of knowing."

Obviously, the intent is for these methods to be overridden. But how would a method like this be implemented? Is native code required?

(Note: On Windows 2000, the method getSystemTypeDescription returns null for all 9 of my drives -- apparently because "no native information is available.")
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The FileSystemView class is an abstract factory/wrapper class. In order to work with it you have to call the getFileSystemView() method.

You then get a platform specific implementation.

I tried it just now and for the Windows platform it successfully detects the floppy drive, harddisk and network drives but the problem is with cdrom drives. It does not seem to work correctly if no cdrom is inserted. An exception is thrown then. You can catch it of course so that is not a real problem.

Now you will have to test the return value (desc) and do with it what you like. It will probably return something different on a different OS. Beware of this.



[ June 30, 2005: Message edited by: Manuel Moons ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manuel: I see it now! Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!