-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-classify-files-by-year.py
executable file
·72 lines (57 loc) · 1.54 KB
/
01-classify-files-by-year.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
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
#!/bin/python2.7
# -*- coding: UTF-8 -*-
## 将原始目录的组织结构进行调整,按照年份将文件放置到对应年份的目录中
import os
DIRS = ["2010", "2011", "2012", "2013", "2014", "2015", "2016"]
TOPDIR = "stdata/"
RESDIR = "resdir"
def _check_dir(path):
if not os.path.isdir(path):
os.mkdir(path)
def check_dir():
for i in DIRS:
_check_dir(TOPDIR+i)
_check_dir(RESDIR)
def _rename_id(id1, lls, c=1):
id2 = "%s-%d" % (id1, c)
if id2 in lls:
id2 = _rename_id(id1, lls, c+1)
return id2
def _move_pdf(src, dst):
if os.path.exists(dst):
print("DST<%s> EXISTS!" % dst)
else:
os.rename(src, dst)
def classify_1516():
lls = []
files = os.listdir("2015")
for i in files:
x = i.split(".")
t = x[0][:6]
if t in lls:
t = _rename_id(t, lls)
lls.append(t)
dst = TOPDIR + "2015/" + t + ".pdf"
_move_pdf("2015/"+i, dst)
def _classify_1214(i, t, lls, d):
if t in lls:
t = _rename_id(t, lls)
lls.append(t)
dst = TOPDIR + d + t + ".pdf"
_move_pdf("2012-2014/"+i, dst)
return lls
def classify_1214():
lls = []
lls13 = os.listdir("stdata/2013/")
for i in lls13:
lls.append(i.split(".")[0])
files = os.listdir("2013")
for i in files:
x = i.split(".")
t = x[0][:6]
u = x[0][6:]
if t in lls:
t = _rename_id(t, lls)
lls.append(t)
dst = TOPDIR + "2013/" + t + ".pdf"
_move_pdf("2013/"+i, dst)