Fixed bug in clear_directory (fails if directory does not exist)

This commit is contained in:
Michael Diodone
2014-10-14 10:48:57 +02:00
parent 7ebc019a40
commit 77eada76c4

View File

@@ -37,15 +37,16 @@ def clear_directory(directory):
"""
Remove the content of a directory recursively but not the directory itself.
"""
for entry in os.listdir(directory):
path = os.path.join(directory, entry)
try:
if os.path.isdir(path):
shutil.rmtree(path, True)
else:
os.unlink(path)
except Exception as e:
print(e)
if os.path.exists(directory):
for entry in os.listdir(directory):
path = os.path.join(directory, entry)
try:
if os.path.isdir(path):
shutil.rmtree(path, True)
else:
os.unlink(path)
except Exception as e:
print(e)
def copy_media_files(from_dir, to_dir):