Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying Mapped drive from local drive

Tags:

java

java-io

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

like image 583
vignesh kumar rathakumar Avatar asked Nov 13 '22 20:11

vignesh kumar rathakumar


1 Answers

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.

like image 184
durron597 Avatar answered Nov 15 '22 11:11

durron597