0

i'm using FileUtils of Commons.IO and i'm trying to create a backup script, the simple rules is to copy from source to dest directory all files (and subdirs) that don't exist in dest or if source has a lastmodified date newer than other.

I can not understand if FileUtils.copyDirectory() is the right choice than how can I set the right FileFilter.

Thank you.

Tobia
  • 9,165
  • 28
  • 114
  • 219

2 Answers2

0

The FilenameFilter only matches the names of files or directories. It cannot help you with the decision whether or not to include an item based on existence in a different tree. However, copyDirectory() seems to do the right thing for your needs, just inefficiently - if you want to exclude unchanged files from the copying you need to add that logic yourself. (The solution could still make use of copyDirectory() internally, unless you want the date comparison to happen on every level.)

Kilian Foth
  • 13,904
  • 5
  • 39
  • 57
  • I mean FileFilter not FilenameFilter, maybe i have to create my own FileFilter and check if file from src exsist in dest folder and check modify time... i think i can do it but i have to find dest file just from src absolute path... – Tobia May 09 '12 at 09:50
0

as @romain points out in his comment to the question rsync would be very efficient for this (only copying changes, including changes within files)

Having said that, you would have to compare that file you get in the file filter with the "same" file in the other directory, just change the top part of the file path and check them.

Or for something that performs better look into the java 7 I/O improvements regarding file system directory traversal. Performs better than Commons FileUtils.

Mattias Isegran Bergander
  • 11,811
  • 2
  • 41
  • 49