I'm trying to add 0 before 1-9 only. 10+ won't have the 0. Here's the function I have so far...
$i++;
$x=0 ;
if(@$checkDir = opendir($dir))
{
$cDir = 0;
$cFile = 0;
// check all files in $dir, add to array listFile
while($file = readdir($checkDir))
{
if($file != "." && $file != "..")
{
if(is_dir($dir . "/" . $file))
{
$listDir[$cDir] = $file;
$cDir++;
}
else
{
$listFile[$cFile] = $file;
$cFile++;
}
}
}
// rename files
if(count($listFile) > 0)
{
sort($listFile);
for($k = 0; $k < count($listFile); $k++)
{
$spacer = "";
for($l = 0; $l < $i; $l++)
$spacer .= " ";
// get the extention of the file
$ext = explode(".", $listFile[$k]) ;
// display what it does
print("") ;
//rename the file
if(@rename($dir . "/" . $spacer . $listFile[$k], $dir . "/" . $name . ($k+1) . "." . $ext[1]))
$x++ ;
else
{
// display message if error append
print("") ;
}
}
}
// closing directory
closedir($checkDir);
print("") ;
}
else
{
// display message if error append
print("") ;
}