Script เปลี่ยนชื่อไฟล์ (เปลี่ยน prefix)


 
'''
Create by @mossila
usage 
python renamer.py <dir> <oldprefix> <newprefix>
ex.
python renamer.py . woman women
'''
import os, shutil,sys
oldprefix = sys.argv[2];
newprefix = sys.argv[3]
def renamer(target) :
  os.chdir(target)
  for filename in os.listdir('.'):
    if filename.startswith(oldprefix) > -1:
      print "old filename=",filename
      newfilename = filename.replace(oldprefix, newprefix);
      os.rename(filename, newfilename)
      print "renamed "+filename + " to " + newfilename
renamer(sys.argv[1])
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s