From 354ce6be53953daed986aafdf6132f3ca277fb96 Mon Sep 17 00:00:00 2001 From: pacmano1 <44065187+pacmano1@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:59:28 -0500 Subject: [PATCH] Create create_dir.js --- create_dir.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 create_dir.js diff --git a/create_dir.js b/create_dir.js new file mode 100644 index 0000000..24009c8 --- /dev/null +++ b/create_dir.js @@ -0,0 +1,19 @@ +/** + * Creates a directory if it does not already exist. + * + * @param {String} dir - The path of the directory to create. Can be absolute or relative. + * + * This function attempts to create the directory specified by the `dir` parameter. + * It first checks if the directory already exists. If it does not, it tries to create the directory + * and all necessary parent directories. If the directory cannot be created, logs an error message. + */ +function create_dir(dir) { + var directory = new java.io.File(dir); + if (!directory.exists()) { + var created = directory.mkdirs(); + if (!created) { + logger.error("Failed to create the directory."); + } + return; + } +}