31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
|
import os
|
||
|
import shutil
|
||
|
from pypinyin import lazy_pinyin, Style
|
||
|
|
||
|
# 指定文件夹路径
|
||
|
folder_path = r"G:\ready\绝天神印"
|
||
|
|
||
|
# 遍历文件夹中的文件
|
||
|
for filename in os.listdir(folder_path):
|
||
|
# 获取文件的完整路径
|
||
|
file_path = os.path.join(folder_path, filename)
|
||
|
|
||
|
# 判断是否为文件
|
||
|
if os.path.isfile(file_path):
|
||
|
# 根据文件名进行拆分
|
||
|
parts = filename.split('-')
|
||
|
|
||
|
# 获取拆分后列表中的第2个值
|
||
|
if len(parts) >= 2:
|
||
|
target_folder_name = parts[1].strip()
|
||
|
target_folder_first_letter = ''.join(lazy_pinyin(target_folder_name[0], style=Style.FIRST_LETTER))
|
||
|
target_folder = target_folder_first_letter.upper() + '-' + target_folder_name
|
||
|
print(target_folder)
|
||
|
|
||
|
# 创建目标文件夹(如果不存在)
|
||
|
save_path = folder_path + '/' + target_folder
|
||
|
if not os.path.exists(save_path):
|
||
|
os.makedirs(save_path)
|
||
|
|
||
|
# 移动文件到目标文件夹
|
||
|
shutil.move(file_path, os.path.join(save_path))
|