From 6743c96a5c212a390dc77b9ed572146264a59492 Mon Sep 17 00:00:00 2001 From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com> Date: Thu, 8 Feb 2024 15:56:23 +0100 Subject: [PATCH] Refactor delete_temp_contents function to handle absolute paths --- src/backend/delete_temp_contents.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/delete_temp_contents.py b/src/backend/delete_temp_contents.py index 5eabca7..583de9c 100644 --- a/src/backend/delete_temp_contents.py +++ b/src/backend/delete_temp_contents.py @@ -1,13 +1,22 @@ import os from omegaconf import OmegaConf +from pathlib import Path config = OmegaConf.load("config.yaml") def delete_temp_contents(): """ delete_temp_contents deletes the contents of the temp directory. """ - for root, dirs, files in os.walk(config.database.tempdir): + path = config.database.tempdir + path = path.replace("~", str(Path.home())) + path = Path(path) + path = path.resolve() + for root, dirs, files in os.walk(path): for file in files: os.remove(os.path.join(root, file)) for dir in dirs: - os.rmdir(os.path.join(root, dir)) \ No newline at end of file + os.rmdir(os.path.join(root, dir)) + + +if __name__ == "__main__": + delete_temp_contents() \ No newline at end of file