Created
August 4, 2021 11:43
-
-
Save gh640/2ca8a994285b45b341ae88abe43ae865 to your computer and use it in GitHub Desktop.
Sample: Delete all items in a directory without deleting the directory itself
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
import shutil | |
from pathlib import Path | |
def delete_directory(path: str): | |
"""Delete a directory.""" | |
for item in Path(path).iterdir(): | |
if item.is_dir(): | |
shutil.rmtree(item) | |
else: | |
item.unlink() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment