Advertisement
rfmonk

renameRE.py

Dec 17th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. #! /usr/bin/env python
  2. import subprocess
  3. import argparse
  4. import re
  5.  
  6. # Parse command line arguments.
  7.  
  8. # Run a Bash command and send output to a list seperated by line.
  9.  
  10. # Change name function
  11. def changeName(oldName, newNameBase):
  12.     temp = re.split('([0-9]+)',oldname)
  13.     newName = newNameBase + temp[1] + temp[2]
  14.     subprocess.call(["mv", oldName, newName])
  15.  
  16. # Change names of all files matching base
  17. def changeAllNames(oldNameBase, newNameBase):
  18.     files = runBash("ls")
  19.     for afile in files:
  20.         temp = re.split('([0-9]+)',afile)
  21.         if temp[0] == oldNameBase:
  22.             changeName(afile,newNameBase)
  23.  
  24. # Change files with base inputFileName to base outputFileName
  25. changeAllNames(args.inputFileName,args.outputFileName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement