TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [TCLUG:18790] quick way to strip spaces...





> -----Original Message-----
> From: Brian Ackermann [mailto:brian_ackermann@bbros.com]
> Sent: Friday, June 09, 2000 2:31 PM
> To: tclug
> Subject: [TCLUG:18790] quick way to strip spaces...
>
>
> anybody got a quick way strip spaces from a filename, preferably one that
> will do globbing and perhaps recursion?
>
> I've got a whole bunch of mp3 uploaded to my new RIMPS server, from various
> places, and I'd really like to eliminate the spaces in the names.  Rimps
> works just fine with them, but its troublesome to me...
>

A little while ago I posted a perl one-liner that converted filenames to
lowercase...  But I can't find it.

Well, it was *something* like this:

perl -e 'opendir D, "."; for(readdir D) {$x=$_; s/\s+/_/g; rename $x, $_;}'

This should convert all spaces to underscores in the directory.  If you'd rather
get rid of them entirely, or only modify files that end in ".mp3", well, you
figure it out.

For bonus points, it's fairly easy to add a recursive loop to traverse
subdirectories.  However, bash's command history should make this optional
unless you've got a *lot* of subdirs.

Test before using!