-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup.py
More file actions
36 lines (31 loc) · 923 Bytes
/
cleanup.py
File metadata and controls
36 lines (31 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# cleanup.py
import os
cPth = r"C:\aaa"
cLog = r"C:\log.txt"
def cleanOver(big):
for r, d, f in os.walk(cPth, False):
for name in f:
ful = os.path.join(r, name)
siz = os.path.getsize(ful)
if siz >= big:
try:
hLog.write("Try removing %s\n"%ful)
os.remove(ful)
except Exception as e:
hLog.write("%s\n"%e)
for name in d:
ful = os.path.join(r, name)
try:
hLog.write("Try removing %s\n"%ful)
os.rmdir(ful)
except Exception as e:
hLog.write("%s %s\n"%(type(e),e))
def myPri(header):
print(header)
for r, d, f in os.walk(cPth, False): print(r, d, f)
hLog = open(cLog, "w")
myPri("Before")
cleanOver(2)
myPri("After" )
hLog.close()
raw_input("Done")