Add a helper to delete a folder
This commit is contained in:
parent
90468b8889
commit
8814702e6b
1 changed files with 26 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
package dev.zontreck.ariaslib.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -21,5 +22,30 @@ public class FileIO
|
|||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursively delete a directory
|
||||
* @param directory The folder to delete
|
||||
*/
|
||||
public static void deleteDirectory(File directory) {
|
||||
if (directory.exists()) {
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteDirectory(file);
|
||||
} else {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Now directory is empty, so delete it
|
||||
directory.delete();
|
||||
System.out.println("Directory deleted: " + directory.getAbsolutePath());
|
||||
} else {
|
||||
System.out.println("Directory does not exist: " + directory.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue