32 lines
844 B
Python
32 lines
844 B
Python
|
|
import os
|
|||
|
|
import shutil
|
|||
|
|
|
|||
|
|
# 花色映射
|
|||
|
|
suit_map = {
|
|||
|
|
"spade": "S",
|
|||
|
|
"heart": "H",
|
|||
|
|
"club": "C",
|
|||
|
|
"diamond": "D"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 创建cards文件夹,不存在就新建
|
|||
|
|
target_dir = "cards"
|
|||
|
|
if not os.path.exists(target_dir):
|
|||
|
|
os.mkdir(target_dir)
|
|||
|
|
|
|||
|
|
# 遍历当前目录所有文件
|
|||
|
|
for fname in os.listdir("."):
|
|||
|
|
# 只处理png文件,格式:花色-数字/字母.png
|
|||
|
|
if fname.endswith(".png") and "-" in fname:
|
|||
|
|
name_no_ext = fname[:-4]
|
|||
|
|
suit_name, rank = name_no_ext.split("-", maxsplit=1)
|
|||
|
|
if suit_name not in suit_map:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 新文件名:点数+花色缩写.png
|
|||
|
|
new_name = f"{rank}{suit_map[suit_name]}.png"
|
|||
|
|
new_path = os.path.join(target_dir, new_name)
|
|||
|
|
|
|||
|
|
# 移动并重命名
|
|||
|
|
shutil.move(fname, new_path)
|
|||
|
|
print(f"{fname} → {new_path}")
|