Skip to content

Instantly share code, notes, and snippets.

@Karasiq
Last active February 11, 2022 14:50
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 Karasiq/d285a9f127775558ef85a8b7e49c73a1 to your computer and use it in GitHub Desktop.
Save Karasiq/d285a9f127775558ef85a8b7e49c73a1 to your computer and use it in GitHub Desktop.
Clean sbt target directories
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