Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
Created January 19, 2011 03:57
Show Gist options
  • Select an option

  • Save shihongzhi/785666 to your computer and use it in GitHub Desktop.

Select an option

Save shihongzhi/785666 to your computer and use it in GitHub Desktop.
重命名文件
import glob,os
if __name__ == '__main__':
p=r'E:\test1\*.jpg'
li = glob.glob(p)
k = 0
for f in li:
i = f.rindex('\\')
j = f.rindex('.')
newf = f.replace(f[i+1:j],'%04d'%(k))
k += 1
try:
os.rename(f,newf)
print "chenggong"
except:
print "shibai"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment