I find that my filesystem likes filespecs to start with a full or relative path
<?php
$i=1;
$a='am.txt';
$p='pm.txt';
$dir1 = './generic/'; // asumption on my part subfolder of current
$dir2 = './playlists/'; //ditto
while($i<=12) {
echo " copying $i\n"; //feedback dont know how large the files are, how much time for copy, if vanishingly small, remove
if (!copy($dir1.$i.$a, $dir2.$i.$a)) { echo "failed to copy $i$a\n"; }
if (!copy($dir1.$i.$p, $dir2.$i.$p)) { echo "failed to copy $i$p\n"; }
$i++; } ?>
it makes no difference the order the files are copied in, the filesytem allocates as it sees fit, as long as the names are the expected names, they will appear in the right order in the code that (eventually) creates the final playlist, (LAZY)