Skip to content

Instantly share code, notes, and snippets.

@jackeylu
Created April 27, 2014 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackeylu/11335940 to your computer and use it in GitHub Desktop.
Save jackeylu/11335940 to your computer and use it in GitHub Desktop.
naming a batch of files with sequence index
# coding: utf-8
import glob
files = glob.glob("*") # get the file list of current directory
out = open("m.bat","w") # generate bat file
i = 1 # where the index start from
for f in files:
newname = "%03.d%s" %(i,f) # output new file name like 001filename, 002filename
out.writelines("move %s %s\n"%(f, newname))
i = i +1
out.close()
# all right now, run the m.bat in shell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment