Skip to content

Instantly share code, notes, and snippets.

@lonsty
Created December 28, 2020 02:24
Show Gist options
  • Save lonsty/04663cca5cb1550b1efe19a42214aaf7 to your computer and use it in GitHub Desktop.
Save lonsty/04663cca5cb1550b1efe19a42214aaf7 to your computer and use it in GitHub Desktop.
Rename files in bulk
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