mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
jdb: Enhance delete functionality to support directory deletion
This commit is contained in:
@@ -116,9 +116,15 @@ public class JDB {
|
|||||||
/**
|
/**
|
||||||
* Deletes the document(s) at the specified path.
|
* Deletes the document(s) at the specified path.
|
||||||
*
|
*
|
||||||
* @param path the relative path (excluding .json extension) where the document(s) are located
|
* @param path the relative path (excluding .json extension) of the document(s) to be deleted
|
||||||
*/
|
*/
|
||||||
public void delete(@NotNull String path) {
|
public void delete(@NotNull String path) {
|
||||||
|
File file = new File(baseDirectory, path);
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
deleteDirectory(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
File documentFile = new File(baseDirectory, createFilePath(path));
|
File documentFile = new File(baseDirectory, createFilePath(path));
|
||||||
if (documentFile.exists()) {
|
if (documentFile.exists()) {
|
||||||
documentFile.delete();
|
documentFile.delete();
|
||||||
@@ -134,4 +140,18 @@ public class JDB {
|
|||||||
private String createFilePath(@NotNull String path) {
|
private String createFilePath(@NotNull String path) {
|
||||||
return path + FILE_EXTENSION;
|
return path + FILE_EXTENSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteDirectory(File directory) {
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File f : files) {
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
deleteDirectory(f);
|
||||||
|
} else {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
directory.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
rootProject.name = "FancySitula"
|
|
||||||
|
|
||||||
include(":api")
|
|
||||||
include(":factories")
|
|
||||||
include(":implementations")
|
|
||||||
include(":implementations:1_20_6")
|
|
||||||
include(":implementations:1_21")
|
|
||||||
include(":implementations:1_21_1")
|
|
||||||
include(":implementations:1_21_3")
|
|
||||||
include(":implementations:1_21_4")
|
|
||||||
|
|
||||||
include(":test_plugin")
|
|
||||||
Reference in New Issue
Block a user