Skip to content

Instantly share code, notes, and snippets.

@Cvetomird91
Last active July 26, 2018 14:55
Show Gist options
  • Save Cvetomird91/c4e57bd667e79f2dc47656b38b213495 to your computer and use it in GitHub Desktop.
Save Cvetomird91/c4e57bd667e79f2dc47656b38b213495 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2.4
import os
import string
path = "/var/spool/asterisk/monitor/"
def make_safe_filename(file):
safechars = string.letters + string.digits + "-_."
try:
return filter(lambda c: c in safechars, file)
except:
return ""
pass
for root, dirs, files in os.walk(path):
for name in files:
checkname = make_safe_filename(name)
if name != checkname:
os.rename(root+'/'+name, root+"/"+checkname)
print name, "has been renamed to ", checkname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment