Created
May 23, 2020 08:59
-
-
Save gh640/c9c280bf01d8bfff782c188efc2f62f3 to your computer and use it in GitHub Desktop.
特定のディレクトリの下の `png` ファイルのファイル名を一括で変更するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """特定のディレクトリの下の `png` ファイルのファイル名を一括で変更するスクリプト""" | |
| from pathlib import Path | |
| PARENT_DIR = Path(__file__).parent / 'rename' | |
| STR_SRC = '.' | |
| STR_DST = '_' | |
| def main(): | |
| for file in png_files(): | |
| rename(file) | |
| def png_files(): | |
| yield from PARENT_DIR.glob('*.png') | |
| def rename(file: Path): | |
| new_target = file.with_name( | |
| '{}{}'.format(file.stem.replace(STR_SRC, STR_DST), file.suffix) | |
| ) | |
| file.replace(new_target) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment