[CLUE-Talk] Re: gensup, was: Re: [CLUE-Tech] removing spaces from filenames?

Jed S. Baer thag at frii.com
Mon Nov 18 12:36:30 MST 2002


On Mon, 18 Nov 2002 12:00:07 -0700
Dave Price <davep at kinaole.org> wrote:

> It runs w/out errors when I exec gawk explicitely - my
> /etc/alternatives/awk was mawk - But the filename need to be protected
> with quotes somehow - when I have a dir named 'Dir with Spaces' it tries
> to 'mv Dir Dir' - also craps out on filenames like: (1)dj1-4.gif
> (because of the parens?)
> 
> Still trying - I did find an mp3rename.pl which works nicely, but:
> 
> 1> won't rename dirs (folders)
> 2> won't recurse (I just got a boatload of windows-ripped albums and I
> need to merge them into my collection so that my shell scripts can play
> them right)

Figger'd there was more to it.

Well, if the clue site were up and running, you could browse the e-mail
archive for the varied suggestions and scripts for doing this sort of
stuff. This one doesn't recurse. Pipe ls output throught it, i.e.:

  ls --color=no | fixdosnames

#!/usr/bin/perl -w
#
# fixdosnames - perl script

sub fixnames {

  shift;

# get rid of URL-encoded characters

  s/\%[0-9]{2}/_/g;

# convert to lower, and get rid of punctuation marks

  tr/A-Z/a-z/;
  tr' -~!@#$%^&*(){}|\":;?<>,[]+='_'s;
  tr/'/_/s;

# get rid of multiple and leading underscores

  s/_+/_/g;
  s/^_+//g;

  return $_
}

while (<>) {

  chomp;
  $oldname = $_;
  $newname = fixnames($oldname);

  if ($oldname ne $newname) {
    print "mv -- $oldname $newname\n";
    @sargs = ("mv", "--", "$oldname", "$newname");
    system(@sargs) == 0 or print
      "unable to move file $oldname: $?\n";
  }

}

-- 
We're frogs who are getting boiled in a pot full of single-character
morphemes, and we don't notice. - Larry Wall; Perl6, Apocalypse 5



More information about the clue-talk mailing list