Skip to content

Instantly share code, notes, and snippets.

@hipertracker
Last active September 17, 2022 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hipertracker/0fb6e6199673bf1d1c59cc1fa5308d45 to your computer and use it in GitHub Desktop.
Save hipertracker/0fb6e6199673bf1d1c59cc1fa5308d45 to your computer and use it in GitHub Desktop.
import os
def rename_folders(path, dirs, src, dst):
for name in os.listdir(path):
if re.match(dirs, name):
name2 = re.sub(src, dst, name)
filepath1 = path + os.sep + name
filepath2 = path + os.sep + name2
os.rename(filepath1, filepath2)
if __name__ == '__main__':
rename_folders(
path='/Volumes/Bydle4TB/FILMY',
dirs=r'^\d{4} - ',
src=r'^(\d{4}) - (.+)',
dst=r'\2 (\1)'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment