Created
October 12, 2016 14:37
-
-
Save qiyuangong/3f720ab16f1f313e6f0c66548afa92a3 to your computer and use it in GitHub Desktop.
Rename nature numbered files with fixed size number
This file contains 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
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