Skip to content

Instantly share code, notes, and snippets.

@gh640
Created May 23, 2020 08:59
Show Gist options
  • Select an option

  • Save gh640/c9c280bf01d8bfff782c188efc2f62f3 to your computer and use it in GitHub Desktop.

Select an option

Save gh640/c9c280bf01d8bfff782c188efc2f62f3 to your computer and use it in GitHub Desktop.
特定のディレクトリの下の `png` ファイルのファイル名を一括で変更するスクリプト
"""特定のディレクトリの下の `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