#! perl -w
use RISCOS;
use RISCOS::File 'copy';

if ($ARGV[0] eq '-q') {
    $quiet = 1;
    shift;
} else { $quiet = 0 }

die "$0 [-q] <From> <To>" if( $#ARGV < 1 );

$sourcedir = shift;
$destdir = shift;


sub get_dir
{
    local ($from, $to) = @_;
    local ($file, $len);

    $len = 1 + length $to;

    foreach $file (glob ("$to.*"))
    {
	$file = substr ($file,$len);
	#print "$to.$file\n";
	if (-d "$to.$file")
	{
	    print "Recursing to $to.$file\n" unless $quiet;
	    get_dir ("$from.$file", "$to.$file");
	}
	else
	{
	    if (-f ("$from.$file"))
	    {
		if (-M (_) != -M ("$to.$file"))
		{
		    #print("copy $from.$file $to.$file ~cvnf\n");
		    copy "$from.$file", "$to.$file", 0x1112 or print STDERR "$!\n";
		}
	    }
	    else {
		warn ("'$from.$file' does not exist.\n") unless $quiet;
	    }
	}
    }
}

get_dir ($sourcedir, $destdir);
