[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: stripping characters during copy process? Problem mp3 filenames



On Thu, Jan 05, 2012 at 06:59:00PM -0800, keitho@strucktower.com wrote:
> I have a bunch of cdroms containing mp3's that I want to copy from the
> cdrom to a vfat partition on a mounted drive on my network. For
> completeness let me say that the drive is a hard drive in an enclosure
> connected via usb. Using a simple cp command I get error messages, not
> sure what they mean. Here is an example:
> 
> keith@t520:~/evesdb4/mp3/misc$cp -vr /media/cdrom0/*.mp3 ./
> `/media/cdrom0/01 Zephyr & I.mp3' -> `./01 Zephyr & I.mp3'
> cp: reading `/media/cdrom0/01 Zephyr & I.mp3': Input/output error
> cp: failed to extend `./01 Zephyr & I.mp3': Input/output error
> `/media/cdrom0/01 All I Want To Do.mp3' -> `./01 All I Want To Do.mp3'
> cp: reading `/media/cdrom0/01 All I Want To Do.mp3': Input/output error
> cp: failed to extend `./01 All I Want To Do.mp3': Input/output error
> 
I would try copying a few files one-by-one to make sure you know for sure which
files cp is choking on.  You might also try using rsync, to see if it
handles things any differently.

Silly question:  does vfat support spaces in filenames?  I recall
something about that feature, a lawsuit by Microsoft, and a patch by
Andrew Tridgell...

> I am assuming (maybe incorrectly) that the problem has to do with the
> spaces and special characters in the filenames.
> 
> Maybe a correct use of quotes would help the globbing problem?
> 
> But my preference would be to use a command syntax or small script that
> would replace all the non-aphanumeric characters with an underscore as
> well as change the case to all lower case during the copy process.
> 
> I've looked around and can find lots of suggestions using some combination
> of rename, awk, sed, find, etc but I can't seem to apply them to my
> situation because I can't write to the cdrom and because I'm dealing with
> a vfat partition, not ext. I have thousands of these mp3's. And they are
> in multiple layers of subdirectories.
> 
I use rename and qmv like this:

# Rename files all lowercase, with underscores instead of spaces:
rename 'y/A-Z,\ /a-z,_/' *.mp3

# Rename files all lowercase, with underscores instead of spaces,
# commas, or parentheses:
rename 'y/A-Z,[\ \,\(\)]/a-z,_/' *.mp3

qmv -f do *.mp3

qmv opens up the filenames in an editor and you can find/replace
characters.  It's not very automated, but still useful.

For rename, maybe you can come up with a command that replaces
everything that is not a-z or A-Z or a number, with an underscore.  This 
doesn't work, but maybe someone could correct it:

rename 'y/[!(A-Z),!(a-z),!(0-9)]/_/' *.mp3

Alternatively you could just specify every special character that you
can think of and change it to an underscore:

rename 'y/[\ \,\(\)\+\&\!\@\#\$\%\^\=\<\>\?\/\"\'\{\}\[\]\:\;\~\`]/_/' *.mp3

-Rob


Reply to: