add stats to emptydir
- ID
c7792f1- date
2022-10-01 08:25:56+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
6a9ad06- message
add stats to emptydir- changed files
1 file, 14 additions, 1 deletion
Changed files
emptydir (998) → emptydir (1267)
diff --git a/emptydir b/emptydir
index 7119660..eb0f132 100755
--- a/emptydir
+++ b/emptydir
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""
This script walks a directory tree, looks for empty directories,
and removes them.
@@ -9,6 +9,9 @@ It prints the name of every directory it removes.
import os
import shutil
+import humanize
+import termcolor
+
def can_be_deleted(d):
# This is a folder where I put files that I explicitly don't
@@ -34,6 +37,16 @@ def delete_directory(d):
if __name__ == "__main__":
+ total_deleted = 0
+
for d, _, _ in os.walk("."):
if can_be_deleted(d):
delete_directory(d)
+ total_deleted += 1
+
+ if total_deleted > 0:
+ print(
+ termcolor.colored(
+ f"{humanize.intcomma(total_deleted)} directories deleted", "green"
+ )
+ )