I often have code where I loop over a directory (including subdirectories) and need to move / copy the file to a different directory. What I find tedious is the process of identifying where the file will go. I have often done that, usually like this:
File shadow = new File(sourceFile.getAbsolutePath()
.replace(
sourceFolder.getAbsolutePath(),
targetFolder.getAbsolutePath()
)
);
My question: is there a standard routine to do this or something similar in any major open source library? I didn't find one in Commons IO anyway...
I am not looking for complete move / copy solutions, I know tons of those. I just want the equivalent of the above code.
An Example, as requested:
Source folder:
src/main/resources
Target folder:
target/classes
Source file:
src/main/resources/com/mycompany/SomeFile.txt
Target file (the one I'm looking for):
target/classes/com/mycompany/SomeFile.txt
(I usually do stuff like this in a maven context, hence these folders but they could be non-maven folders, as well, the question has nothing to do with maven)