use File::Copy;
#use File::KGlob;
use Time::localtime;


$tm=localtime;

$thedate = sprintf("%04d%02d%02d", $tm->year+1900, $tm->mon+1, $tm->mday);


$oldfile = $ARGV[0];

unless ( -e $oldfile ) {
	printf("Can't find $oldfile to backup!\n");
	exit;
}

$i = 1;
$newfile = "";
while ( $newfile eq "" ) {
	$newfile = $oldfile . "." . $thedate . sprintf("%02d",$i);
	if ( -e $newfile ) {
		#printf("newfile exists\n");
		#printf("Try again.\n");
		$newfile = "";
	}
	$i++;
}


#AskToCopyFile();
#printf("Okay, I will copy the file.\n");
copy($oldfile, $newfile);


sub AskToCopyFile {

	printf("Backup %s to %s?\n", $oldfile,$newfile);
	$answer = <STDIN>;
	chomp $answer;
	unless ( $answer eq "Y" || $answer eq "y" || $answer eq "yes") {
		printf("Abort.\n");
		exit;
	}




}
