Reply to Re: rename function not working ???

Your name:

Reply:


Posted by noone on 02/23/06 19:25

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);

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация