Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rename nature numbered files with fixed size number
import os
def rename_nature_with_fixed_size(size=3, sep='_'):
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
if sep in f and f[0] != sep:
new_name = f.split(sep)
if len(new_name[0]) < size:
new_name[0] = '0' * (size - len(new_name[0])) + new_name[0]
os.rename(f, sep.join(new_name))
if __name__ == "__main__":
rename_nature_with_fixed_size()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.