I wrote this function below to find all folders named 'Construction Documents', I want it to copy all its contents over to another directory.
private void findDirectory(File parentDirectory, String insertDir) {
if(foundFolder) {
return;
}
File[] files = parentDirectory.listFiles();
for (File file : files) {
if (file.isFile()) {
continue;
}
if (file.getName().equals("Construction Documents")) {
System.out.println(file.getAbsolutePath());
if(file.getParent().contains("Original") || file.getParent().contains("Revision") || file.getParent().contains("R0")){
new File(insertDir + file.getParent()).mkdir();
try {
// FileUtils.copyDirectory(new File(file), new File(insertDir + file.getParent().toString()));
Files.copy(file.toPath(), new File(insertDir + file.getParent().toString()).toPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
if(file.isDirectory()) {
findDirectory(file, insertDir);
}
}
}
insertDir is the String of the file path id like to insert the folder in. I tried using FileUtils, however this copied the ENTIRE directory over, including the many parent files before the actual construction documents folder. Native java didnt work either, and simply led to errors.
In short, I would like to copy a single folder, with all its subfolders and contents over to another folder, however without all the parent files from the copied file being created on the destination end.