3
Some time ago I did this question about recursive search in folders, and now I need to adapt to a different condition.
I need to copy only the names of the subfolders from a higher folder to a third one, but without copying the most internal files and folders, that is, I need to "clone" the first level subfolders without taking their content along.
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;
}
It is possible to adapt this method to the reported problem?
But won’t that work recursively, like the question? Because what would get in the way of me now copying the first level of directories is the recursion sweeping out other subfolder levels.
– user28595
@diegofm changed to respond without recursiveness
– Sorack
I adapted in a different way but the base I used the same filtrardiretorios method, worth :D
– user28595
@diegofm avail. Just one thing, maybe this method of
filtrarDiretorios
could return only oneList<String>
. I don’t know if it would have much impact this change, but I think it makes more sense– Sorack
I thought about it too but I check some other things that File is more viable than String, so I returned File, to facilitate.
– user28595