Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pathlib import Path
- import os
- folder = input('folder relative to this script: ')
- ext = input('extension (don\'t include period): ')
- target = int(input('# digits: '))
- for path in (Path('.') / folder).glob(f'*.{ext}'):
- n, *rest = path.stem.split(' ', 1)
- rest = ''.join(rest)
- n = n.zfill(target)
- name = f'{n} {rest}'.strip() + f'.{ext}'
- os.rename(path, path.parent / name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement