Refactor delete_temp_contents function to handle absolute paths
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user