Created
November 21, 2015 11:17
-
-
Save rm--/666db176ed07c7fdb134 to your computer and use it in GitHub Desktop.
list comprehension to bulk rename files
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
| pip install natsort | |
| import os | |
| src_dir = '/tmp/in' | |
| dst_dir = '/tmp/out' | |
| starting_nb = 11 # new filename starting with this number | |
| [os.rename(src_dir + os.sep + f,dst_dir + os.sep + str(i) + '.' + f.split('.')[1]) for (i,f) in enumerate(natsort.natsorted(os.listdir(src_dir)),starting_nb)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment