CoolFace
Apppublic

AvinaashA/DualView-BMI

sourceHugging Facemitupdated 9mo agoView on Hugging Face
1likes
empty.py17 linesDownload Raw Back to root
1import os
2import shutil
3
4def empty_directory(directory_path):
5    # Check if the directory exists
6    if os.path.exists(directory_path):
7        # Remove all contents of the directory
8        for item in os.listdir(directory_path):
9            item_path = os.path.join(directory_path, item)
10            if os.path.isfile(item_path) or os.path.islink(item_path):
11                os.unlink(item_path)  # Remove file or symlink
12            elif os.path.isdir(item_path):
13                shutil.rmtree(item_path)  # Remove directory
14    else:
15        print(f"Directory {directory_path} does not exist.")
16
17