5

I am listing all available drives in my desktop using File.listRoots() in Java. I have some Mapped drives. When I list the roots it is fetching me local drives as well as mapped drives. In order to exclude the mapped drives I used following code snippet:

for (File drive :File.listRoots()){
   String typeDescription = FileSystemView.getFileSystemView().getSystemTypeDescription(drive);
}

Based on the type description returned I am filtering the drive. But this is not universally standard and not acceptable by other operating system. Only supported for windows. Also there is a language restriction (English only supported for type description). Can any one give me any other solution to filter the mapped drives globally.

Note:
It must be specific to JDK1.6

  • 1
    Any other solution will be platform specific. But since _All available drives_ is a solely a Windows term you're probably looking for windows only solution? – Oleg Mikheev Oct 16 '12 at 04:35
  • @Oleg Mikheev. Yeah.. I am looking only for solution in windows.But in linux machine File.listRoots() returns only Root dir. So no problem in Linux. I need to distinguish between mapped drive and local drive in windows platform... – vignesh kumar rathakumar Oct 16 '12 at 04:45
  • Deleted my answer. I just tried it on OS X and I see the problem you're having. I will post another answer if I think of anything. – Dave Oct 18 '12 at 12:01

1 Answers1

1

If your problem is only in Windows, why not use:

if (System.getProperty("os.name").contains("Windows")) ?

You could write a C++ program to do it (human) language independently using IVdsDisk::GetProperties, and then import it as a native function in Java (and tell the VM only to try to run the native method if you're running Windows.

MSDN link to get you started

Check to see if VDS_DISK_PROP.dwMediaType is a FILE_DEVICE_NETWORK or a FILE_DEVICE_NETWORK_FILE_SYSTEM. You can see all the supported types here: winioctrl.h

It's possible that value is accessible in Java, but Java generally doesn't have platform specific stuff so I doubt it.

durron597
  • 31,968
  • 17
  • 99
  • 158
  • @durron597.. I can differentiate OS using code snippet which you have mentioned above.. But think this scenario, when I have Installed windows OS in different language other than english I can not use the "Type description" to differentiate the mapped drives and local drives. If I want to differentiate them through the "type description" I have to check for OS language before I identifying map drive from local drive. It may lead to number of conditional checking as many languages as found in windows Os. – vignesh kumar rathakumar Oct 25 '12 at 04:00
  • @vigneshkumarrathakumar: I updated the post, that may help you! – durron597 Oct 25 '12 at 12:54