For some time I've done this question about recursive search in folders, and now I need to adapt to a different condition.
I need to copy just the names of subfolders from a top folder to a third folder, but without copying the most internal files and folders, that is, I need to "clone" the top-level subfolders without bringing their content together.
ex.:
-Pasta root
|-subpasta1✅
|-sub-subpasta1(esse nivel não pode ser copiado)
|-subpasta2 ✅
|-subpasta3✅
|-subpasta4✅
...
|-subpastaN✅
I'm currently using a suggested method in the linked question to filter files:
private static List<File> filtrarArquivos(File source, String pattern) throws IOException {
List<File> fileList = new ArrayList<>();
Files.walk(source.toPath()).forEach(arquivo -> {
if (arquivo.getFileName().toString().matches(pattern)) {
fileList.add(arquivo.toFile());
}
});
return fileList;
}
Is it possible to adapt this method to the reported problem?