37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
package io.gitlab.jfronny.inceptum.launcher.system.exporter;
|
|
|
|
import io.gitlab.jfronny.commons.io.JFiles;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.*;
|
|
import java.nio.file.attribute.BasicFileAttributes;
|
|
|
|
public class CleanupFileVisitor implements FileVisitor<Path> {
|
|
@Override
|
|
public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
|
|
if (JFiles.list(path).isEmpty()) {
|
|
Files.delete(path);
|
|
return FileVisitResult.SKIP_SUBTREE;
|
|
}
|
|
return FileVisitResult.CONTINUE;
|
|
}
|
|
|
|
@Override
|
|
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) {
|
|
return FileVisitResult.CONTINUE;
|
|
}
|
|
|
|
@Override
|
|
public FileVisitResult visitFileFailed(Path path, IOException e) {
|
|
return FileVisitResult.CONTINUE;
|
|
}
|
|
|
|
@Override
|
|
public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException {
|
|
if (Files.exists(path) && JFiles.list(path).isEmpty()) {
|
|
Files.delete(path);
|
|
}
|
|
return FileVisitResult.CONTINUE;
|
|
}
|
|
}
|