daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Aug 15th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re, glob, os
  2.  
  3. def renamer(files, pattern, replacement):
  4.     for pathname in glob.glob(files):
  5.         basename= os.path.basename(pathname)
  6.         new_filename= re.sub(pattern, replacement, basename)
  7.         if new_filename != basename:
  8.             os.rename(
  9.               pathname,
  10.               os.path.join(os.path.dirname(pathname), new_filename))
  11.  
  12. # example:
  13. # renamer("*.*", r"(.*)review-(.*)\.(.*)", r"\1-review-\2.\3")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top