Skip to content

Instantly share code, notes, and snippets.

@dobrokot
Created November 3, 2014 13:38
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 dobrokot/0dc57346b5429b42b8e4 to your computer and use it in GitHub Desktop.
Save dobrokot/0dc57346b5429b42b8e4 to your computer and use it in GitHub Desktop.
strip punctiation from file names
import os, re
fs = []
for x in os.listdir('.'):
if x.endswith('.mp4'):
fs.append((os.path.getsize(x), x))
fs2 = []
for s, x in sorted(fs):
m = re.match('kikoriki[ -]*([0-9]+)(.*)-[-_A-Za-z0-9]{11}[.]mp4', x.lower())
assert m
name = '_'.join(''.join(re.findall('[ a-z0-9]', m.group(2).lower())).split())
fs2.append((x, int(m.group(1)), name))
for i, (x, n, name) in enumerate(fs2):
#new_name = '%03d_%03d_%s.mp4' % (i, n, name)
new_name = '%03d_%s.mp4' % (n, name)
os.link(x, ('../ap/' + new_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment