summaryrefslogtreecommitdiff
path: root/Chap9PracDelUnneed.py
diff options
context:
space:
mode:
Diffstat (limited to 'Chap9PracDelUnneed.py')
-rw-r--r--Chap9PracDelUnneed.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Chap9PracDelUnneed.py b/Chap9PracDelUnneed.py
new file mode 100644
index 0000000..f277c0d
--- /dev/null
+++ b/Chap9PracDelUnneed.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+
+# Chapter 9 Practice Selective Copy
+# Walks through a directory tree searching for files > 100MB and deletes them.
+
+import os
+
+def deleteUnneeded(folder):
+ folder = os.path.abspath(folder)
+ for foldername, subfolders, filenames in os.walk(folder):
+ for filename in filenames:
+ fileSize = os.path.getsize(foldername + '/' + filename)
+ if int(fileSize) < 10000000:
+ continue
+ #os.unlink(filename) #Commented out to protect against accidental deletion
+ print('Deleting ' + filename + '...') #Print only to verify working correctly
+
+deleteUnneeded('/Users/username/Documents')
+print('Done')