Skip to content

Commit

Permalink
add an excludeExtensions list to CoreUtil.copyDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 15, 2020
1 parent 63eadd4 commit b1c8274
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -136,7 +136,7 @@ else if (!dexists && !d.getParentFile().exists()) {
d.getParentFile().mkdirs();
}
if (o.isDirectory()) {
CoreUtilities.copyDirectory(o, d);
CoreUtilities.copyDirectory(o, d, null);
}
else {
Files.copy(o.toPath(), (disdir ? d.toPath().resolve(o.toPath().getFileName()) : d.toPath()));
Expand Down
Expand Up @@ -376,13 +376,23 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
});
}

public static void copyDirectory(File source, File destination) throws IOException {
copyDirectory(source.toPath(), destination.toPath());
public static void copyDirectory(File source, File destination, HashSet<String> excludeExtensions) throws IOException {
copyDirectory(source.toPath(), destination.toPath(), excludeExtensions);
}

public static void copyDirectory(Path source, Path destination) throws IOException {
public static void copyDirectory(Path source, Path destination, HashSet<String> excludeExtensions) throws IOException {
Files.walk(source).forEach(file -> {
try {
if (excludeExtensions != null) {
String name = file.getFileName().toString();
int dot = name.indexOf('.');
if (dot >= 0) {
String ext = toLowerCase(name.substring(dot + 1));
if (excludeExtensions.contains(ext)) {
return;
}
}
}
Files.copy(file, destination.resolve(source.relativize(file)));
}
catch (IOException ex) {
Expand Down

0 comments on commit b1c8274

Please sign in to comment.