#!/usr/bin/perl -w
use File::Copy;
# get rid of parens around sci. names (may have side effects)

# input record separator a tag not a newline

# program to search and replace strings in html files
#my $olddir = "./pictures";
#my $newdir = "./clnpics";
#my $olddir = "./gigs";
#my $newdir = "./clngigs";
#my $olddir = "./articles";
#my $newdir = "./clnarts";
my $olddir = "./setlists";
my $newdir = "./clnset";
#my $olddir = "./posters";
#my $newdir = "./clnpost";
#my $olddir = "./others";
#my $newdir = "./clnoth";
opendir(DIR, "$olddir") || die("cannot open $olddir");
foreach $file (readdir(DIR)) {
my $new = $file;

$new =~ s/JPG/jpg/g;
$new =~ s/jpeg/jpg/g;
$new =~ s/GIF/gif/g;
$new =~ s/\s+/_/g;
$new =~ s/#//g;
$new =~ s/!//g;
$new =~ s/'//g;
$new =~ s/,/_/g;
# these are all the metachars to remove:
$new =~ s/\^/_/g;
$new =~ s/\$/_/g;
$new =~ s/\*/_/g;
$new =~ s/\+/_/g;
$new =~ s/\?/_/g;
$new =~ s/\(/_/g;
$new =~ s/\)/_/g;
$new =~ s/\[/_/g;
$new =~ s/\]/_/g;
$new =~ s/\{/_/g;
$new =~ s/\}/_/g;
$new =~ s/\\/_/g;
$new =~ s/\|/_/g;
# other fixes
$new =~ s/\@/_at_/g;
$new =~ s/\&/_and_/g;
$new =~ s/___/_/g;
$new =~ s/__/_/g;
$new =~ s/--/-/g;
$new =~ s/_-/_/g;
$new =~ s/-_/_/g;
$new =~ s/^A-Za-z0-9-_.//g;
if ($new  =~ /(\d\d\d\d)-(\D.*)(\.jpg|\.png)/) {
  $new = $1 . "-xx-xx-" . $2 . $3;
}
$new =~ s/-xx-xx-xx-xx-/-xx-xx-/g;

copy("$olddir/$file","$newdir/$new");
}
close (DIR);
#rename($old, "old.orig");
#rename($new, $old);
