0

I am trying to copy a directory, and do so successfully with Apache Commons IO's FileUtils.

I want however to be able to choose if the copy should merge the folders, with either the source or the destination taking precedence. The API-docs tells me that the source takes precedence now, but I can't find a way to undo that.

Also, all of the copyDirectory methods seems to include all subfolders and files. I would like to be able to choose if I want them to tag along or not. I have tried to explore the FileFilter parameter option, but the API does not really provide much info about the class, and I haven't been able to find relevant uses of it, for my problem in other ways either.

EDIT: I have changed the question from "How can I" to "Can I", as it is suggested that my request is not possible with Fileutils. Confirmation on that, will be accepted as an answer, per to the new formulation of the question.

jumps4fun
  • 3,994
  • 10
  • 50
  • 96

1 Answers1

0

If you want the destination files to take precedence you can use a procedure like this:

  • Copy sourceDir to a tmpDir
  • Copy destDir to the tmpDir
  • Copy tmpDir to destDir
  • Delete tmpDir
  • Well, that would work, but I was hoping for a sleeker solution. – jumps4fun May 02 '14 at 10:03
  • Indeed, this way you have to do three directory copies instead of one, which has a crazy performance impact. But I don't think you have any other option with FileUtils. Maybe with another library... – Lefteris Koutsoloukas May 02 '14 at 10:10