Skip to content

Commit

Permalink
delete folders as well as files
Browse files Browse the repository at this point in the history
  • Loading branch information
treee111 committed Oct 16, 2024
1 parent a4a99a8 commit 767548e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions wahoomc/file_directory_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,22 @@ def delete_o5m_pbf_files_in_folder(folder):
pass


def delete_all_files_in_folder(folder):
def delete_everything_in_folder(folder):
"""
delete all files ald directories of given folder
"""
files_and_folders = list(os.listdir(folder)) # [f for f in os.listdir(folder)]

for file in files_and_folders:
try:
os.remove(os.path.join(folder, file))
file_or_dir = os.path.join(folder, file)
# file or dir?
if os.path.isfile(file_or_dir):
# delete file
os.remove(file_or_dir)
else:
# delete directory if exists. copytree fails if dir exists already
shutil.rmtree(file_or_dir)
except OSError:
pass

Expand Down
4 changes: 2 additions & 2 deletions wahoomc/setup_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pkg_resources

# import custom python packages
from wahoomc.file_directory_functions import delete_all_files_in_folder, write_json_file_generic, \
from wahoomc.file_directory_functions import delete_everything_in_folder, write_json_file_generic, \
read_json_file_generic, copy_or_move_files_and_folder
from wahoomc.constants_functions import get_tooling_win_path, get_absolute_dir_user_or_repo
from wahoomc.downloader import get_latest_pypi_version
Expand Down Expand Up @@ -58,7 +58,7 @@ def adjustments_due_to_breaking_changes():
platform.system() == "Windows":
log.info(
'Last run was with version %s, deleting Windows Tooling files of %s directory due to possible bad files.', version_last_run, USER_TOOLING_WIN_DIR)
delete_all_files_in_folder(USER_TOOLING_WIN_DIR)
delete_everything_in_folder(USER_TOOLING_WIN_DIR)


def check_installation_of_required_programs():
Expand Down

0 comments on commit 767548e

Please sign in to comment.