Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sebastianschramm/c7ebca61f4666828fdd822731654e41a to your computer and use it in GitHub Desktop.
Save sebastianschramm/c7ebca61f4666828fdd822731654e41a to your computer and use it in GitHub Desktop.
How to get all files in directory and delete them?
from pathlib import Path
def delete_all(directory_path: Path):
if directory_path.is_dir():
for file in directory_path.iterdir():
file.unlink(missing_ok=True)
if __name__ == "__main__":
directory_with_file = Path("data/assets")
delete_all(directory_with_file)
@sebastianschramm
Copy link
Author

dependencies: python3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment