#!/usr/bin/python # Nathan DeBardeleben # ndebard@parl.clemson.edu # 8/8/2002 # # This script takes a collection of files (example: jpgs) in subdirectories # off of the working directory. It renames the files XXXXXXXX.ZZZ where # X... is a monotonically increasing number starting at the initial number. # These files are MOVED from their original directories and placed in the # working directory. import re, os, string, sys help = "echo */*.jpg | "+sys.argv[0]+" -s " if len(sys.argv) != 3: print help sys.exit(0) init = sys.argv[2] number = int(init) for line in sys.stdin.readlines(): list = string.split(line) for word in list: loc = string.rfind(word, ".") rhs = "" if loc != -1: rhs = word[loc+1:] # this is silly, but simple if number < 10: lhs = "0000000"+str(number) elif number < 100: lhs = "000000"+str(number) elif number < 1000: lhs = "00000"+str(number) elif number < 10000: lhs = "0000"+str(number) elif number < 100000: lhs = "000"+str(number) elif number < 1000000: lhs = "00"+str(number) elif number < 10000000: lhs = "0"+str(number) elif number < 100000000: lhs = str(number) else: print "Cannot handle numbers this big." sys.exit(0) print "Link: "+word+" to "+lhs+"."+rhs number = number + 1 os.system("ln -s "+word+" "+lhs+"."+rhs) #os.link(word, lhs+"."+rhs) #os.rename(word, lhs+"."+rhs)