#!/usr/bin/perl -dw
# Move files with names of the form NN-* into the BookNN directories.
# This is a temp script, to be discarded.

$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 2;	# Verbose level.

$MV = '/Users/jc/bin/Mv.sh';

for $arg (@ARGV) {
    unless (($NN,$rest) = ($arg =~ /^(\d\d)(.*)$/)) {
        print "Skip\t\"$arg\"\n" if $V>1;
    }
    print "File\t\"$arg\"\n" if $V>1;
    if (($N,$tail) = ($rest =~ /^-_(\d)-(.*)$/)) {
        print "NN-D-\t'$NN' '$N' '$tail'\n" if $V>1;
        $path = "../Book$NN/${NN}__$N-$tail";
    } else {
        print "NN*\t'$NN' '$rest'\n" if $V>1;
        $path = "../Book$NN/$arg";
    }
    $cmd = "$MV '$arg' '$path'";
    print "CMD:\t$cmd\n" if $V>0;
    if (system $cmd) {
        print STDERR "#### Can't MV \"$arg\" [$!]\n" if $V>0;
    } else {
        ;
    }
}

exit $exitstat;
