private static void addFiles(File dir, List<File> collection) throws IOException {
   File[] files = dir.listFiles();
   List<File> subDirs = new ArrayList<>(2);
   for (int i = 0; i < files.length; i++) {
     if (files[i].isFile()) {
       collection.add(files[i]);
     } else if (files[i].isDirectory()) {
       subDirs.add(files[i]);
     }
   }
   Iterator<File> iter = subDirs.iterator();
   while (iter.hasNext()) {
     File subDir = iter.next();
     addFiles(subDir, collection);
   }
 }
 public static void importFilesFromDirectory(
     File rootDir, IPath destPath, IProgressMonitor monitor)
     throws InvocationTargetException, IOException {
   IImportStructureProvider structureProvider = FileSystemStructureProvider.INSTANCE;
   List<File> files = new ArrayList<>(100);
   addFiles(rootDir, files);
   try {
     ImportOperation op =
         new ImportOperation(
             destPath, rootDir, structureProvider, new ImportOverwriteQuery(), files);
     op.setCreateContainerStructure(false);
     op.run(monitor);
   } catch (InterruptedException e) {
     // should not happen
   }
 }