Created
May 17, 2024 08:21
-
-
Save ArthurDelannoyazerty/0c4b1a7b0473e8d4ec8a90ed08378612 to your computer and use it in GitHub Desktop.
Recursively delete the content of a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def delete_content_folder(folder:str): | |
for filename in tqdm(os.listdir(folder), desc="Erasing Temporary Data", leave=False): | |
file_path = os.path.join(folder, 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment