I am trying to create a simple function which copies or merge two or more folder files into one single folder.
I started with below. I thought to post here to get a better quality code.
public void copyDifferentFolderFilesIntoOne(String mergedFolderStr,String ... foldersStr)
{
File mergedFolder= new File(mergedFolderStr);
for(String folder: foldersStr)
{
//copy folder's files into mergedFolder
}
}
When there is a conflict in file copying (i.e. file with same name exists on two or more folder) I want the file with latest timestamp get copied in mergedFolder.
Do you know the best way to merge two or more folders files into one?
Let me know if question is not clear.
You can create a
Map<String, File>of the files you want to copy by traversing the merged dirs and keeping the newest files. Then you can copy the files you have in a map.A sample code (haven’t tried it) might look like this: