package de.hftstuttgart.dtabackend.utils; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; /** * Helper Class for all file related tasks. * * Created by Marcel Bochtler on 05.01.17. */ public class FileUtil { /** * Delete the folder and all containing files. * @param folder Folder to delete */ public static void deleteFolderRecursively(File folder) { File[] files = folder.listFiles(); if (files != null) { for (File f : files) { if (f.isDirectory()) { deleteFolderRecursively(f); } else { f.delete(); System.out.println(String.format("Deleted file: %s", f.getAbsolutePath())); } } } folder.delete(); System.out.println(String.format("Deleted folder: %s", folder.getAbsolutePath())); } public static void copyFolder(Path src, Path dst) throws IOException { Files.walk(src) .forEach(source -> { try { Files.copy(source, dst.resolve(src.relativize(source))); System.out.println(String.format("Copying file from: %s to %s", source.toString(), dst.resolve(src.relativize(source)).toString())); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }); } }