Fixing Filenames

Both programs work great, with the exception of stripping special characters–like ‘,’ ‘<‘ or ‘#’–from filenames. SoundJuicer has an option marked “Strip Special Characters,” but it doesn’t always work. Some special characters–anything with an accent mark above it, for instance–it won’t ever strip. Since Rhythmbox chokes on filenames with special characters, you have to change the filename before it’ll play the file.

This is tedious to do manually, so I wrote a Python script to do it for me. It’s not very elegant, but it gets the job done: invoke it from the command line followed by a path to the directory containing the files you need stripped of special characters, and it takes care of the rest.

Here’s the code:

#!/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 <http://www.gnu.org/licenses/&gt;.

Rhythmbox won’t play a file with accented characters in the filename. Otherwise what I have now would work fine for everything else I do.

SoundJuicer doesn’t strip any of the special characters I’ve put in the above program: commas, less than or greater than signs, ‘#’ signs, accented characters, etc. Since they show up more often in music files than I thought at first, I’ll take your suggestion and file a bug report.