Have a look at this, I think it should do it !
/* for($intA = 0; $intA < 101; $intA++) {
$intNumero = (($intA < 100) ? '0' : '') . (($intA < 10) ? '0' : '') . $intA;
$resFichier = fopen('./Test_PHPB/filename.' . $intNumero . '.tif', 'w+');
fclose($resFichier);
}*/
function Retourner_Nouvelle_Serie($intDebut, $intFin) {
$strDebut = ((($intDebut < 100) ? '0' : '') . (($intDebut < 10) ? '0' : '') . $intDebut);
$strFin = ((($intFin < 100) ? '0' : '') . (($intFin < 10) ? '0' : '') . $intFin);
return sprintf('%s.[%s-%s].tif', $GLOBALS['strNom_Fichier'], $strDebut, $strFin);
}
$strNom_Fichier = 'filename';
$resRepertoire = opendir('./Test_PHPB/');
$intDebut = 0;
$intFin = 0;
while(!(($strFichier = readdir($resRepertoire)) === false)) {
$strMotif = '#^[^\.]*?\.([\d]{3})\.tif$#';
$arrCaptures = array();
if(($strFichier <> '.') && ($strFichier <> '..') && (preg_match($strMotif, $strFichier, $arrCaptures) > 0)) {
$intNumero = intval($arrCaptures[1]);
if($intNumero > ($intFin + 1)) {
echo Retourner_Nouvelle_Serie($intDebut, $intFin) . "<br />\n";
$intDebut = $intNumero;
}
$intFin = $intNumero;
}
}
echo Retourner_Nouvelle_Serie($intDebut, $intFin) . "<br />\n";
closedir($resRepertoire);
The first part, which is "commented" was simply used to create the files, I let it there just in case... I deletes some files (013, 047, 053, 064, 079), and it gave me this output :
filename.[000-012].tif
filename.[014-046].tif
filename.[048-052].tif
filename.[054-063].tif
filename.[065-078].tif
filename.[080-100].tif
As you can see, that's all in French ! English should not always rule ! 😛 😛
Debut = Start
Fin = End
Nom_Fichier = Filename
Fichier = File
Repertoire = Directory
Let me know if it helped 😉