-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoomrlCleanup.py
More file actions
executable file
·31 lines (26 loc) · 911 Bytes
/
Copy pathdoomrlCleanup.py
File metadata and controls
executable file
·31 lines (26 loc) · 911 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
#!/usr/bin/python
import os, re
dateExtract = re.compile("\[(\d*)-(\d*)-(\d*)\D*(\d*)-(\d*)-(\d*)\]")
dateGet = re.compile("\D*(\d*)-(\d*)-(\d*)\D*(\d*):(\d*):(\d*)")
def cleanup(dirToClean, beforeDate):
"A function that cleans up DoomRL's mortem and screenshot folder. :)"
os.chdir(dirToClean)
#get directory list
for file in os.popen("dir").readlines():
noDelete = 0
#get file; ignore '!readme.txt'
if file[0] != '!':
file = file.rstrip()
TestDate = re.match(dateExtract, file).groups() #get day file was taken
#this is to decide whether to delete file or not
for i in range(6):
if int(beforeDate[i]) > int(TestDate[i]):
break
else:
noDelete = 1
# POSIX systems on if; windows on elif
if noDelete == 0 and os.name == 'posix':
os.system("rm %s" % file)
elif noDelete == 0 and os.name[:3] == 'win':
os.system("del %s" % file)
os.chdir('..')