Skip to content

Instantly share code, notes, and snippets.

@atulkumar2
Created July 28, 2018 15:52
Show Gist options
  • Save atulkumar2/a234dae5e6e04adcc746e7d1e207b475 to your computer and use it in GitHub Desktop.
Save atulkumar2/a234dae5e6e04adcc746e7d1e207b475 to your computer and use it in GitHub Desktop.
Rename all folders with group matching and wildcard matching
# Search for files and folders whose names matches pattern 'M*S*'
# and rename those to names like 'M0*S*'
import os, re, glob
for item in glob.glob('^M*S*'):
print(item)
os.rename(item, re.sub(r'(\d)', r'0\1', item, count=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment