$dir = "img1";
$fileType = "jpg";
$charsToTrim = 4;
if($handle = opendir($dir))
{
$count = 1;
while (false !== ($file = readdir($handle)))
{
if(is_file($dir."\\".$file))
{
$extension = substr(strrchr($file,"."),1);
if(strcasecmp($fileType,$extension) == 0)
{
// $newName = substr($file,$count);
$newName = $count;
$success = rename($dir."\\".$file, $dir."\\".$newName.'.'.$extension);
if($success)
{
echo $file." renamed to ".$newName;
echo "
";
$count++;
}
else
{
echo "Cannot rename ".$file. " to ".$newName."
";
echo "
";
}
}
}
}
echo $count." files renamed";
}
closedir($handle);
0 comments:
Post a Comment