From 767548eaa9a91e1fdc6353eb0056ba1782997633 Mon Sep 17 00:00:00 2001 From: Benjamin Kreuscher Date: Wed, 16 Oct 2024 11:54:36 +0200 Subject: [PATCH] delete folders as well as files --- wahoomc/file_directory_functions.py | 11 +++++++++-- wahoomc/setup_functions.py | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/wahoomc/file_directory_functions.py b/wahoomc/file_directory_functions.py index ed87db38..14e05426 100644 --- a/wahoomc/file_directory_functions.py +++ b/wahoomc/file_directory_functions.py @@ -131,7 +131,7 @@ 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 """ @@ -139,7 +139,14 @@ def delete_all_files_in_folder(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 diff --git a/wahoomc/setup_functions.py b/wahoomc/setup_functions.py index f41db150..8f63ac22 100644 --- a/wahoomc/setup_functions.py +++ b/wahoomc/setup_functions.py @@ -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 @@ -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():