@Test public void readDirectoryWithFiles() throws Exception { TemporaryFile tf = new TemporaryFile(true); File f1 = new File(tf.getFile(), "x"); FileContentWorker.set_contents(f1, "x"); File f2 = new File(tf.getFile(), "y"); FileContentWorker.set_contents(f2, "y"); Set<File> f = DirectoryReader.listAllRecursively(tf.getFile()); assertEquals(2, f.size()); assertTrue(f.contains(f1)); assertTrue(f.contains(f2)); tf.delete(); }
public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; }
DirectoryReader { public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; } }
DirectoryReader { public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; } private  DirectoryReader(); }
DirectoryReader { public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; } private  DirectoryReader(); static Set<File> listAllRecursively(File directory); }
DirectoryReader { public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; } private  DirectoryReader(); static Set<File> listAllRecursively(File directory);  }