#!/usr/bin/env python # -*- coding: utf-8 -*- import os, sys, re files = [f for f in os.listdir('.') if os.path.isfile(f) and f.startswith(sys.argv[1])] for f in files: print f match = re.match(r'([a-zA-Z.]*).(S[0-9]*E[0-9]*).([a-zA-Z0-9äöüÄÖÜß\-\.\,\w]*)', f) newName = match.group(1) + "-" + match.group(2) + "-" + match.group(3) print newName os.rename(f, newName) print "\n"