Created
December 28, 2020 02:24
-
-
Save lonsty/04663cca5cb1550b1efe19a42214aaf7 to your computer and use it in GitHub Desktop.
Rename files in bulk
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
from os import listdir, rename | |
from os.path import isfile, join | |
from sys import argv | |
mypath = argv[1] | |
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] | |
for file in sorted(onlyfiles, reverse=True): | |
first, name = file.split(']') | |
index = int(first[1:]) | |
new_file = f'[{index+1:02d}]{name}' | |
rename(f'{mypath}/{file}', f'{mypath}/{new_file}') | |
print(f'Renamed {mypath}/{file} to {mypath}/{new_file}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment