How can I get list all drives but also get the corresponding drive type (removable,local disk, or cd-rom,dvd-rom... etc)?
The correct way is how Luciano answered with isRemovable property, but I recently had on win 10 that if I started from USB, then USBs were no longer found in that method.
So, I used, for Windows only, the following wmic calls:
ArrayList rootDirs = new ArrayList();
if( isWin )
{
if( i_dolog )
LOG.info( "Windows found as OS." );
ArrayList partids = new ArrayList();
String results0 = execute( "wmic diskdrive where interfacetype='USB' assoc /assocclass:Win32_DiskDriveToDiskPartition" );
String lines[] = results0.split( "\r\r\n" );
for( String line : lines )
{
String test = "Win32_DiskPartition.DeviceID=";
int index = line.indexOf( test );
if( index >= 0 )
{
String partid = line.substring( index + test.length() + 1 );
partid = partid.substring( 0, partid.indexOf( '"' ) );
partids.add( partid );
}
}
for( String partition : partids )
{
String results2 = execute( "wmic partition where (DeviceID='" + partition + "') assoc /assocclass:Win32_LogicalDiskToPartition" );
String lines2[] = results2.split( "\r\r\n" );
for( String line : lines2 )
{
String test = "Win32_LogicalDisk.DeviceID=";
int index = line.indexOf( test );
if( index >= 0 )
{
String partid = line.substring( index + test.length() + 1 );
partid = partid.substring( 0, partid.indexOf( '"' ) );
rootDirs.add( new File( partid + "\\" ) );
}
}
}
}