#!/usr/bin/perl

if ($#ARGV != 1) {
  print "Correct command usage: \n";
  print "   perl convert.pl [DIRECTORY_TO_CONVERT] [NEW_DIRECTORY]\n";
}

$olddir = $ARGV[0];
$newdir = $ARGV[1];

@problem = `ls -B $olddir/ | grep -v bak`;
chomp @problem;

for($index=0;$index<=$#problem;$index++) {
  $newprob = $problem[$index];
  $newprob =~ s/txt/problem/;
#  $newprob = $newprob.".problem";
  open( CONVERT, ">$newdir/$newprob" );
  print CONVERT "<problem>\n";
  $convert =
`/home/felicia/loncapa/loncom/homework/CAPA-converter/Linux/convert -f
$olddir/$problem[$index]`;
  print CONVERT "$convert";
  print CONVERT "\n</problem>\n";
  close CONVERT;
}

