-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_directory.py
More file actions
executable file
·71 lines (50 loc) · 1.76 KB
/
Copy pathclean_directory.py
File metadata and controls
executable file
·71 lines (50 loc) · 1.76 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
# Clear files older than informed number of the days #
# Informe The path of the folder #
# If not informed it will use actual path #
# And the number of the days it will keep the files #
# If this last is not informed the program will delete#
# files older than 60 days #
TODO: One of the first try in Python, everything needs to change
"""
import os
import glob
import sys
import datetime
import re
from time import sleep
if __name__ == '__main__':
folder = os.curdir
if len(sys.argv) > 1:
folder = sys.argv[1]
retDays = 60
if len(sys.argv) > 2:
if re.search('^[0-9]+$', sys.argv[2]):
retDays = sys.argv[2]
os.chdir(folder)
today = datetime.date.today()
#wait to user confirm or cancel
print("It will delete all files in folder ") + folder
print("Older than " + retDays + " Days")
for i in range(0,5):
sleep(1)
sys.stdout.write('.')
sys.stdout.flush()
print ("\n")
retDays = int(retDays)
for name_file in glob.glob('*'):
if os.path.isdir(name_file):
continue
print ("------------------------------------------------------\r")
print (name_file + "\r")
file_stat = os.lstat(name_file)
file_date = datetime.date.fromtimestamp(file_stat.st_mtime)
diference = today - file_date
diference = diference.days
print ("Date:\t\t" + str(datetime.date.isoformat(file_date)))
print ("Today is:\t" + today.isoformat())
print ("diff is:\t" + str(diference))
if diference > retDays:
print('Excluir')
os.remove(name_file)
print("\r")