#!/usr/bin/python # This is a simple python program to look through a directory and # strip special characters from the filenames in that directory. I use # it mostly to fix filenames after importing music from CDs. # Invoke this program from the command line followed by the path to the directory # containing the filenames you want fixed. # # Copyright (C) 2008 Ron Toland # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # long with this program. If not, see . import os, sys replace_list = [ ",", " ", "+", "-", "=", "#", ">", "<", ";", "$", "&", "!"] def namefixer(dummy, dirname, filesindir): for fname in filesindir: newname = fname for item in replace_list: newname = newname.replace(item, "_") os.rename(os.path.join(dirname, fname), os.path.join(dirname, newname)) if __name__ == '__main__': os.path.walk(sys.argv[1], namefixer, None)