-
Notifications
You must be signed in to change notification settings - Fork 1
/
mananumber.hds
65 lines (55 loc) · 1.78 KB
/
mananumber.hds
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
#coding: utf8
#title: Give a number to the Manatoki folder
#author: Hyri Diaz Hayes
#comment: Not yet tested. Recommend to use as reference only.
# Written on 2024-02-04 by Hyri Diaz Hayes
from utils import Hook
import os
def dir2array(path):
folders = []
while 1:
path, folder = os.path.split(path)
if folder != "":
folders.append(folder)
else:
if path != "":
folders.append(path)
break
folders.reverse()
return folders
@Hook.task_finished('rename')
def hook_rename(cw):
if cw.type != 'manatoki':
return
# 다운로드한 파일 경로에서 폴더 경로만 추출
folders = []
for name in cw.names:
folder = os.path.dirname(name)
if folder not in folders:
folders.append(folder)
# 숫자가 붙은 새로운 폴더 생성
for folder in folders:
folderIndex = folders.index(folder)
new_dir_name = dir2array(folder)
new_dir_name[-1] = str(folderIndex).zfill(
4
) + ' ' + new_dir_name[-1]
new_dir = (os.path.join(*new_dir_name))
if not os.path.exists(new_dir):
os.mkdir(new_dir)
# 파일 이름 변경 (* 이동 *)
for i, file in enumerate(cw.names):
folderIndex = folders.index(os.path.dirname(file))
folders2 = dir2array(file)
folders2[-2] = str(folderIndex).zfill(
4
) + ' ' + folders2[-2]
new_name = os.path.join(*folders2)
os.rename(file, new_name)
cw.setNameAt(i, new_name)
# 기존 폴더 삭제
for folder in folders:
if len(os.listdir(folder)) == 0:
os.rmdir(folder)
cw.setChanged()
messageBox('Hooked!')