1
+ #-*- coding: utf-8 -*-
2
+
3
+ from os import path , walk , getcwd
4
+ from openpyxl import Workbook
5
+ from openpyxl .styles import PatternFill , Font
6
+ import sys
7
+
8
+ if sys .argv [1 :]:
9
+ self = ' ' .join (sys .argv [1 :])
10
+ else :
11
+ self = getcwd ()
12
+
13
+ # 폴더의 파일 읽기
14
+
15
+ REMOVES = ['makelist.exe' , 'renamer.xlsx' , 'renamer.exe' ]
16
+
17
+ try :
18
+ walk = list (walk (self ))
19
+ except :
20
+ print ('cannot read directory' )
21
+ quit ()
22
+
23
+ for rem in REMOVES :
24
+ try :
25
+ walk [0 ][2 ].remove (rem )
26
+ except :
27
+ continue
28
+
29
+ items = []
30
+
31
+ for step in walk :
32
+ for folder in step [1 ]:
33
+ items .append ([step [0 ]+ "\\ " + folder + "\\ " ,"" ])
34
+ for file in step [2 ]:
35
+ items .append ([step [0 ]+ "\\ " , file ])
36
+
37
+ # 엑셀 파일 생성
38
+
39
+ wb = Workbook ()
40
+ ws = wb .active
41
+ ws .title = "rename"
42
+ ws .append (['' ,'원래 경로' , '원래 이름' , '변경할 경로' , '변경할 이름' ])
43
+
44
+ for item in items :
45
+ type = ['[파일]' ] if path .isfile ('\\ ' .join (item )) else ['[폴더]' ]
46
+ ws .append (type + item + item )
47
+
48
+ # 시트 스타일링
49
+ c = PatternFill (fill_type = 'solid' , start_color = 'F6F6F6' , end_color = 'F6F6F6' )
50
+ b = Font (bold = True )
51
+
52
+ ws .column_dimensions ['A' ].width = 6
53
+ ws .column_dimensions ['B' ].width = 50
54
+ ws .column_dimensions ['C' ].width = 25
55
+ ws .column_dimensions ['D' ].width = 50
56
+ ws .column_dimensions ['E' ].width = 25
57
+ ws .column_dimensions ['F' ].width = 3
58
+
59
+ for col in ws .iter_cols (min_col = 1 , max_col = 3 ):
60
+ for cell in col :
61
+ cell .fill = c
62
+ for row in ws .iter_rows (min_row = 1 , max_row = 1 ):
63
+ for cell in row :
64
+ cell .font = b
65
+
66
+ # # 안내문
67
+
68
+ # ws.column_dimensions['G'].width = 4
69
+ # ws.column_dimensions['H'].width = 60
70
+
71
+ # t = [
72
+ # "1. 파일",
73
+ # "",
74
+ # "",
75
+ # "2. 폴더",
76
+ # "",
77
+ # "3. 삭제",
78
+ # "",
79
+ # "",
80
+ # "",
81
+ # "만든이.",
82
+ # "공대적 문과생",
83
+
84
+ # "https://velog.io/@m00nlygreat"
85
+ # ]
86
+ # t2 = [
87
+ # "",
88
+ # "- 이름을 변경하면 이름이 변경됩니다.",
89
+ # "- 경로를 변경하면 파일이 이동됩니다. 폴더가 없으면 만듭니다.",
90
+ # "",
91
+ # "- 경로를 변경하면 폴더를 이동합니다. 폴더가 없으면 만듭니다.",
92
+ # "",
93
+ # "- 경로와 이름을 모두 비워두면 파일이든 폴더든 삭제합니다.",
94
+ # "- 주의: 복구 불가. 폴더를 지우면 안의 파일도 모두 삭제됨"
95
+ # ]
96
+ # for i,text in enumerate(t):
97
+ # ws['G'][i].value = text
98
+
99
+ # for i,text in enumerate(t2):
100
+ # ws['H'][i].value = text
101
+
102
+ # 저장
103
+
104
+ try :
105
+ wb .save ('renamer.xlsx' )
106
+ for item in items :
107
+ print (item )
108
+ except :
109
+ print ("error. check if renamer.xlsx is being used" )
0 commit comments