Last active
February 11, 2022 14:50
-
-
Save Karasiq/d285a9f127775558ef85a8b7e49c73a1 to your computer and use it in GitHub Desktop.
Clean sbt target directories
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
if __name__ == '__main__': | |
from pathlib import Path | |
def rmdir(directory, cond): | |
directory = Path(directory) | |
should_delete: bool = cond(directory) | |
try: | |
for item in directory.iterdir(): | |
if item.is_dir(): | |
rmdir(item, lambda d: should_delete or cond(d)) | |
elif should_delete: | |
#print(item) | |
item.unlink() | |
if should_delete: | |
directory.rmdir() | |
print(directory) | |
except Exception as e: | |
print(f"Couldn't delete {directory}: {e}") | |
rmdir(Path("/Users/user/IdeaProjects"), lambda d: d.name == 'target') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment