The problem is that the folder has files with the following name.

Same_name.RTF Same_name.RTF.p7s 

And this method considers the first file as a folder. Persistent and adamant. How can I determine the folder or the file?

  • Do not offer to look for a point, there are folders with it.
  • The first extension may be different.
  • Search goes to the network folder.

Initial option:

 String[] dirList = curentFolder.list((File dir, String name) -> return dir.isDirectory()); 
  • one
    show how you check that the file is a directory, sample code - Artem Konovalov
  • And how are curentFolder initialized? - Mikhail Vaysman
  • and if java.nio.file.Files.isDirectory( Paths.get( "//host/share/folder/filename" ) ) - zRrr

1 answer 1

There is no problem, you are not using the filter correctly.
Namely, if you look at javadoc , it says:

 @FunctionalInterface public interface FilenameFilter { /** * Tests if a specified file should be included in a file list. * * @param dir the directory in which the file was found. * @param name the name of the file. * @return <code>true</code> if and only if the name should be * included in the file list; <code>false</code> otherwise. */ boolean accept(File dir, String name); } 

those. dir is the current directory in which files were found, naturally your filter will always return true

And here is a sample code that should do what you want

 List<String> directories = Files .list(Paths.get("current_directory")) .filter(Files::isDirectory) .map(Path::toString) .collect(Collectors.toList()); System.out.println(directories);