test(FileManager): Added if path exist check

Closes #8347
This commit is contained in:
Noelia 2023-02-24 12:54:05 +01:00 committed by Noelia
parent 7cef444601
commit b4407f79ce
1 changed files with 9 additions and 6 deletions

View File

@ -16,12 +16,15 @@ def erase_directory(dir: str):
os.remove(directory)
def clear_directory(dir: str):
for files in os.listdir(dir):
path = os.path.join(dir, files)
try:
shutil.rmtree(path)
except OSError:
os.remove(path)
if os.path.exists(dir):
for files in os.listdir(dir):
path = os.path.join(dir, files)
try:
shutil.rmtree(path)
except OSError:
os.remove(path)
else:
log("Trying to clear directory but it doesn't exist: " + dir)
def copy_directory(src: str, dst: str):
if os.path.isdir(src) and os.path.isdir(dst):