Skip to content

Instantly share code, notes, and snippets.

@gh640
Created August 4, 2021 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gh640/2ca8a994285b45b341ae88abe43ae865 to your computer and use it in GitHub Desktop.
Save gh640/2ca8a994285b45b341ae88abe43ae865 to your computer and use it in GitHub Desktop.
Sample: Delete all items in a directory without deleting the directory itself
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