0

Tweaking a bit this code: https://stackoverflow.com/a/14676464/962475, I want to have a list of all my folders up to n levels.

public void listf(String directoryName, ArrayList<File> directories, int level, int maxLevel) {

    File directory = new File(directoryName);
    // get all the files from a directory
    File[] fList = directory.listFiles();
    System.out.println(directoryName);
    //testing where it failded
    for (File file : fList) {
        if (file.isDirectory()) {
            directories.add(file);
            if(level<maxLevel)
                listf(file.getAbsolutePath(), directories, level+1, maxLevel);
        }
    }
}

This code gives me an error through - "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"while trying to access "C:\Config.msi" - this is a windows protected folder that, when trying to access using file explorer gives an "access denied" error.

Frankly, I don't really need this folder in my list, but I can't find how to filter folders by system folders. Maybe by getattribute, but couldn't find an appropriate attribute.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
romand
  • 27
  • 4
  • What exactly is null? A nullpointerexception is very different than access denied – OneCricketeer Aug 09 '17 at 00:18
  • where is the exception being throw from? – Scary Wombat Aug 09 '17 at 00:22
  • @Vanna Thank you. This is exactly what I was looking for. Googling/seaching on SO for "java protected/system directories" gave me different results (since java has other meaning for "system" and "protected"). – romand Aug 09 '17 at 00:36

0 Answers0