From e50c19b619487fee6a0a2960f312ef0490148f72 Mon Sep 17 00:00:00 2001 From: kiihne-noaa Date: Fri, 29 May 2026 14:07:26 -0400 Subject: [PATCH 1/2] Create workdir.py for directory structure setup #895 Add initial setup for working directory structure --- fre/run/workdir.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 fre/run/workdir.py diff --git a/fre/run/workdir.py b/fre/run/workdir.py new file mode 100644 index 000000000..8a3b958a5 --- /dev/null +++ b/fre/run/workdir.py @@ -0,0 +1,2 @@ +# ---------------- set up working directory structure + From 697f58a4e93b0c5de9b071f536c47bbe909a738b Mon Sep 17 00:00:00 2001 From: kiihne-noaa Date: Thu, 4 Jun 2026 14:14:31 -0400 Subject: [PATCH 2/2] Implement directory cleanup with exception handling Add functionality to clean working directory while preserving temporary output directory. --- fre/run/workdir.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fre/run/workdir.py b/fre/run/workdir.py index 8a3b958a5..d29db03ba 100644 --- a/fre/run/workdir.py +++ b/fre/run/workdir.py @@ -1,2 +1,25 @@ # ---------------- set up working directory structure +# Need to import variables: workDir, tmpOutputDir +from pathlib import Path +import os +import shutil +import sys +workDir = Path("/path/to/directory") + +if workDir.is_dir(): #checks for existence and if path is directory + if os.access(workDir, os.R_OK | os.W_OK): #checks read and write permissions + for item in work_dir.iterdir(): + #remove everything except temporary directory + if item == tmp_output_dir: + continue + try: + # Delete all files, folders, and links + if item.is_file() or item.is_symlink(): + item.unlink() # Deletes individual files or symlinks + elif item.is_dir(): + shutil.rmtree(item) # Recursively deletes directories (rm -rf) + + except Exception as e: + # Incase of a weird glitch, error instead of crash + print(f"Skipped {item} due to error: {e}")