Dependencies
If you use maven, add this to your pom.xml:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commonsio.version}</version>
</dependency> |
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commonsio.version}</version>
</dependency>
Copy directory
org.apache.commons.io.FileUtils.copyDirectory(srcDir, destDir); |
org.apache.commons.io.FileUtils.copyDirectory(srcDir, destDir);
Copy directory using regular expression as filter
FileFilter filter = element -> element.getName().matches(regex);
org.apache.commons.io.FileUtils.copyDirectory(srcDir, destDir, filter ); |
FileFilter filter = element -> element.getName().matches(regex);
org.apache.commons.io.FileUtils.copyDirectory(srcDir, destDir, filter );
Move directory using regular expression as filter
FileFilter filter = element -> element.getName().matches(regex);
File[] fileList = srcDirectory.listFiles(filter);
for(File file : fileList ) {
file.renameTo(new File(destDir, file.getName()));
} |
FileFilter filter = element -> element.getName().matches(regex);
File[] fileList = srcDirectory.listFiles(filter);
for(File file : fileList ) {
file.renameTo(new File(destDir, file.getName()));
}
Delete directory
org.apache.commons.io.FileUtils.deleteDirectory(srcDir, destDir); |
org.apache.commons.io.FileUtils.deleteDirectory(srcDir, destDir);