Refactor delete_temp_contents function to handle absolute paths

This commit is contained in:
WorldTeacher
2024-02-08 15:56:23 +01:00
parent a33e632e34
commit 6743c96a5c

View File

@@ -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))
os.rmdir(os.path.join(root, dir))
if __name__ == "__main__":
delete_temp_contents()