Reply to Re: file extention - wildcard

Your name:

Reply:


Posted by Steve on 09/21/07 21:44

"Krustov" <me@privacy.net> wrote in message
news:MPG.215e325d9ecaa50e98ad25@news.newsreader.com...
>I have the following list of image files .
>
> When searching the latest (numbered file) in this particular case its
> background_4.*** and its a .jpg file - but - the latest file in the list
> could also be a .gif file at times .
>
> zimages_background/background_1.jpg
> zimages_background/background_2.jpg
> zimages_background/background_3.gif
> zimages_background/background_4.jpg
>
> etc etc
>
> How do i do a wildcard file extention search to find the latest numbered
> image - regardless if its a .jpg or .gif .
>
> I know how to search for the _* number in the filename & its how to do a
> file extention wildcard search i need .
>
>
> --
> (stuckle and his lapdogs are forbidden from replying to this thread as i
> dont actually want any help from them)

hope i'm not one of them...not sure of my association with the lapdogs. if
you mean republican, i tend to go that way on fiscal and domestic policy,
however r's look more d than d's do these days. if you only mean mentally
entrenched to blindly follow...i can assure you i'm not. ;^)

here's a flexible function to list files and one to return the file number,
followed by an example with your data above. if the image doesn't meet
image_number.ext, then the whole file name is returned and the version
number will be zero.

hth,

me

========================


<?
function listFiles($path = '.', $extension = array(), $combine = false)
{
$wd = getcwd();
$path .= substr($path, -1) != '/' ? '/' : '';
if (!chdir($path)){ return array(); }
if (!$extension){ $extension = array('*'); }
if (!is_array($extension)){ $extension = array($extension); }
$extensions = '*.{' . implode(',', $extension) . '}';
$files = glob($extensions, GLOB_BRACE);
chdir($wd);
if (!$files){ return array(); }
$list = array();
foreach ($files as $file)
{
$list[] = ($combine ? $path : '') . $file;
}
return $list;
}
function getImages($value, $key, &$images)
{
$pathInfo = pathinfo($value);
$path = $pathInfo['dirname'];
$fileName = $pathInfo['basename'];
$fileNumber = 0;
$matches = array();
if (preg_match("/^([^_]*?)_(\d+).*$/", $fileName, $matches))
{
$fileName = $matches[1];
$fileNumber = max($images[1][$path][$fileName], $matches[2]);
}
$images[1][$path][$fileName] = $fileNumber;
}
$files = listFiles('zimages_background', null, true);
$images = array();
$imageList = array('', &$images);
array_walk($files, 'getImages', $imageList);
foreach ($images as $path => $files)
{
foreach ($files as $name => $version)
{
echo '<pre>============================</pre>';
echo '<pre>path :: ' . $path . '</pre>';
echo '<pre>file :: ' . $name . '</pre>';
echo '<pre>version :: ' . $version . '</pre>';
}
}
?>

[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

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