Pinyin Rename - 中文文件名转拼音首字母重命名
Batch-rename files so every Chinese character in the filename becomes its
lowercase pinyin initial, while digits, letters, and underscores are left
unchanged.
Example: 胎膜_bg.png -> tm_bg.png, 胎膜_等级进度满.png -> tm_djjdm.png,
裂缝图标.png -> lftb.png.
When to Use
- The user wants filenames with Chinese converted to pinyin initials
(lowercase), preserving digits/letters/underscores and the file extension. - Typical triggers: game/app asset folders (切图), exported design assets,
or any batch of files with mixed Chinese + ASCII names.
How to Execute
Run the bundled script (no third-party dependencies required):
python {skill-dir}/scripts/rename_pinyin.py {target-directory} [--dry-run] [--recursive]
Where {skill-dir} is this skill's installation directory and
{target-directory} is the folder containing the files to rename. Use the
managed Python runtime if available
(C:/Users/Admin/.workbuddy/binaries/python/versions/3.13.12/python.exe).
Recommended workflow:
- First run with
--dry-runto preview the planned renames. - Show the mapping table to the user if the batch is large or ambiguous.
- Remove
--dry-runand execute. - Verify the result with a directory listing
(e.g.,ls -1 <target-directory>).
Behavior Details
- Only files whose names contain Chinese characters are touched; everything
else is left untouched. - Target-name conflicts are never overwritten; they are reported and
skipped (exit code 2). - Characters outside the GB2312 level-1 common set are kept as-is and
reported with a[WARN]line. If this happens, installpypinyin
into the runtime (pip install pypinyin) and rerun for full coverage,
or handle those files manually. - The script prefers
pypinyinwhen available for accurate polyphone
handling (e.g., 重 -> z/zhòng vs c/chóng); otherwise it falls back to the
built-in GB2312 code table, which covers ~3700 most common hanzi.
Notes for Edge Cases
- Polyphonic characters (多音字) may map to an unexpected initial with the
fallback table. When precision matters, installpypinyinfirst. - The script does not lowercase existing ASCII letters (per the rule:
digits, letters, and underscores stay unchanged). If the user asks for
full lowercase, clarify before running. - For folders (directories) rather than files, or for extensions like
.PNG, adapt on request — the core conversion logic in
scripts/rename_pinyin.py(functionconvert_name) is reusable.