Entry 2936
renamer
Submitted by anonymous
on Jan. 6, 2010 at 11:23 p.m.
Language: Python. Code size: 536 bytes.
import glob import string import os #get all the jpg file names in the current folder filetype = raw_input('enter the file type you want to rename:\n') print filetype + "\n" basename = raw_input('enter the base name:\n') print filetype+"\n" files = glob.glob("*.jpg") #sort the list files.sort() count = 0 # and rename each file for f in files: count = count + 1 n = basename + "." +string.zfill(count,4) + ".jpg" print f, n, try: os.rename(f, n) print except: print "error: didn't rename"
This snippet took 0.01 seconds to highlight.
Back to the Entry List or Home.