Hi I have search the net to an extent that I can not more and I still have not found the answer, so I am someone here can tell me, I want to be able to list all local drives in a system, but excluding USB. Network, DVD, etc

This is what I have but I don't know how to pickup only the Local Drive

public class ListAllDrives {
public static void main(String[] args) {

      List <File>files = Arrays.asList(File.listRoots());
      for (File drv : files) {
          String s1 = FileSystemView.getFileSystemView().getSystemDisplayName (drv);
          String s2 = FileSystemView.getFileSystemView().getSystemTypeDescription(drv);
          System.out.println(s2 + " : " + s1);
        }
    }
}

Any suggestion would be greatly appreciated.

There is no such concept as a "local drive". There's just a drive.

Hello again and although I know I ask allot of questions I also like to provide answers when I figure them out and in this case I have achived it with something even more symple than I expected.

public class ListLocalDrives {
public static void main(String[] args) {

      List <File>root = Arrays.asList(File.listRoots());
      for (File drv : root) {
          
        String name = FileSystemView.getFileSystemView().getSystemDisplayName (drv);
        String type = FileSystemView.getFileSystemView().getSystemTypeDescription(drv);
        String local = "Local Disk";

        if ( (type).equals(local) ){
            System.out.println(type + " : " + name);
          }
        }
    }
}

I hope this helps some of those people asking the same questions online.

That might work on some operating systems in some languages, but isn't universal.

You are absolutely correct unfortunately this option only covers Windows and in English I do apologies for those using alternative operating systems and different languages.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.