Yannick Benoit wrote:
Hi guys.
I have like hundreds of pictures in a folder
and then I use this function to rename them
all to a following number. but very often I
noticed that some pictures get lost and I
dont know where ? anyone can tell me
whats wrong ?
$dir = getcwd()."/dump/";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if(($filename <> ".")&&($filename <> "..")){
$pic_ctr++;
rename("dump/".$filename, "dump/".$pic_ctr.".jpg");
}
}
thanx for your help !
not tested, but should work.
$pic_ctr=0; //initialize the picture counter
// if we successully open the dir then continue
if ($dir = @opendir("./dump"))
// we are using relative path
//or you can specify full pathname.
// for example "/home/mydir/dump"
{
while($filename = readdir($dir))
//if filename is a .jpg then rename it...
//sometimes better to check what the name is
// as opposed to what the name is not (your code)
if (eregi("^[a-zA-Z0-9_]+\.jpg", $filename))
{$pic_ctr++;
rename("./dump/".$filename, "./dump/".$pic_ctr.".jpg");
}
}
closedir($dir);