Search code examples
javaapache-commonsapache-commons-iofileutils

Progress bar with Apache FileUtils.copyDirectory(...)


Does anyone know any way of implementing progress bar for Apache's FileUtils.copyDirectory(File src, File dst)? I don't see anything helpful in JavaDocs and API. Seems like a common use case in dealing with batch disk operations, so I'm not sure if I miss something obvious.


Solution

  • I guess you will have to do that yourself. I see this immediate solution:

    1. Find all files you are about to copy and count the number or total file size first (depending on what your progress bar should measure)
    2. Copy the files using FileUtils.copyDirectory(File, File, FileFilter) and "abuse" the FileFilter as a callback to communicate progress to your progress bar