-
Notifications
You must be signed in to change notification settings - Fork 1
/
remrec.py
executable file
·39 lines (33 loc) · 1 KB
/
remrec.py
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
37
38
39
#!/usr/bin/python
"""
remove all recently created files
"""
import os
import sys
import argparse
import datetime
folder = '.'
def modification_date(filename):
t = os.path.getmtime(filename)
return datetime.datetime.fromtimestamp(t)
parser = argparse.ArgumentParser()
parser.add_argument('-r',"--recent", action="store_true" )
parser.add_argument('-h',"--hour",nargs=1,default=0, type=int)
parser.add_argument('-m',"--minutes",nargs=1,default=0, type=int)
args = parser.parse_args()
for file in os.listdir(folder):
# print file + "to" + str(i) + os.path.splitext(file)[1]
mt = modification_date(file)
ct = datetime.datetime.today()
dt = ct - mt
if args.hour:
hour = divmod(c.days * 86400 + c.seconds, 60*60)[0]
if hour < args.hour:
cmd = 'mv ' + file
# os.system(cmd)
elif args.minutes:
minutes = divmod(c.days * 86400 + c.seconds, 60)[0]
if minutes < args.minutes:
cmd = 'ls'+file
# os.system(cmd)
pass