Skip to content

Instantly share code, notes, and snippets.

@Rembane
Last active December 11, 2015 08:38
Show Gist options
  • Save Rembane/4574366 to your computer and use it in GitHub Desktop.
Save Rembane/4574366 to your computer and use it in GitHub Desktop.
Changes the names of all files in a directory to prefix + index + suffix
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
from functools import partial
import os
joincur = partial(os.path.join, os.getcwd())
print "Ange det nya prefixet på filerna: "
prefix = raw_input()
for i, fn in enumerate(os.listdir(os.getcwd())):
newname = "%s%s%s" % (prefix, i, os.path.splitext(fn)[1])
os.rename(joincur(fn), joincur(newname))
print "%s -> %s" % (fn, newname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment