Created
August 16, 2022 12:56
-
-
Save sebastianschramm/c7ebca61f4666828fdd822731654e41a to your computer and use it in GitHub Desktop.
How to get all files in directory and delete them?
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dependencies: python3.9