Something along the lines of....

Code:
foreach ($files as $filename) {

    split_filename($filename, $name, $ext);

    $result = [exec "tonart $filename"];

    $new_filename = $name + "_" + $result + "." + $ext;

    rename($filename, $new_filename);

}
That's pseudocode by the way, as I can't think of the correct stuff off the top of my head.