-
Notifications
You must be signed in to change notification settings - Fork 6
/
文件名识别作品名作者名并新建文件夹移动文件(拖拽,仅多个文件夹,可简繁转换,文件夹名格式[作品][作者]XX).py
42 lines (39 loc) · 1.58 KB
/
文件名识别作品名作者名并新建文件夹移动文件(拖拽,仅多个文件夹,可简繁转换,文件夹名格式[作品][作者]XX).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
# encoding:utf-8
# pip install opencc-python-reimplemented
# https://github.com/wangandi520/andyspythonscript
from opencc import OpenCC
from pathlib import Path
import sys
import re
def main(inputPath):
del inputPath[0]
# 文件名设置成简体 = True,繁体 = False
fileNameType = True
for aPath in inputPath:
if Path.is_dir(Path(aPath)):
folderName = Path(aPath).name
nameParts = re.findall("(\\[[^\\]]*\\])", folderName)
if len(nameParts) >= 2:
if fileNameType:
workName = OpenCC('t2s').convert(nameParts[0][1:-1])
authorName = OpenCC('t2s').convert(nameParts[1][1:-1])
else:
workName = OpenCC('s2t').convert(nameParts[0][1:-1])
authorName = OpenCC('s2t').convert(nameParts[1][1:-1])
authorPath = Path(aPath).parent.joinpath(Path(authorName))
if not authorPath.exists():
Path.mkdir(authorPath)
workPath = Path(authorPath).joinpath(Path(workName))
if not workPath.exists():
Path.mkdir(workPath)
for file in Path(aPath).glob('*'):
oldFilePath = Path(aPath).joinpath(Path(file.name))
newFilePath = Path(workPath).joinpath(Path(file.name))
Path(oldFilePath).replace(newFilePath)
Path.rmdir(Path(aPath))
if __name__ == '__main__':
try:
if len(sys.argv) >= 2:
main(sys.argv)
except IndexError:
pass