private void copyAllFilesToLogDir(File node, File parent) throws IOException { if (!node.getAbsoluteFile().equals(parent.getAbsoluteFile()) && node.isFile() && !node.getParentFile().equals(parent)) { String fileNamePrefix = node.getName().substring(0, node.getName().lastIndexOf('.')); String fileNameSuffix = node.getName().substring(node.getName().lastIndexOf('.')); String newFilePath = node.getParentFile().getAbsolutePath() + File.separator + fileNamePrefix.replace(".", "_") + fileNameSuffix; File newNode = new File(newFilePath); if (node.renameTo(newNode)) { FileUtils.copyFileToDirectory(newNode, parent); } } if (node.isDirectory()) { String[] subNote = node.list(); for (String filename : subNote) { copyAllFilesToLogDir(new File(node, filename), parent); } if (!node.equals(parent)) { FileUtils.deleteDirectory(node); } } }