Skip to content

Commit

Permalink
Add util function to remove a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
plant99 committed Jul 26, 2020
1 parent 51555fd commit 8384811
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions felicette/utils/sys_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import os
import shutil


def exit_cli(print_func, message):
Expand All @@ -16,3 +17,15 @@ def display_file(file_name):

elif sys.platform.startswith("darwin"):
os.system("open %s" % file_name)

def remove_dir(directory):
for filename in os.listdir(directory):
file_path = os.path.join(directory, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print('Failed to delete %s. Reason: %s' % (file_path, e))
exit_cli(print, "")

0 comments on commit 8384811

Please sign in to comment.