Reputation: 628
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
Upvotes: 5
Views: 1029
Reputation: 32323
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.
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.
Upvotes: 1