You are here: Re: Getting the filenames from a folder « PHP Programming Language « IT news, forums, messages
Re: Getting the filenames from a folder

Posted by juglesh on 10/31/05 04:57

Chung Leong wrote:
> I usually use glob() 'cause I'm lazy.
>
> http://fi.php.net/glob/

nice, i never saw that. I assume you could go *.*, can you give it
multiple matches, like *.jpg, *.gif ?

here is a func which can give an array of either folders or files:

$aListOfFiles = GetDirList($someDirectory, 'files');
$aListOfFfolders = GetDirList($someDirectory, 'folders');


function GetDirList($parent, $filesorfolders){
$oldDir = getcwd();
$list = array();

if ($handle = opendir($parent)) {
chdir($parent);
while (false !== ($file = readdir($handle))) {

if ($filesorfolders == "folders"){
if ( (is_dir($file)) && ($file != ".") && ($file !=
".."))
{$list[] = $file;
}}
if ($filesorfolders == "files"){
if ( (is_file($file)) && ($file != ".") && ($file !=
".."))
{$list[] = $file;
}}


}// while reading
closedir($handle);
chdir($oldDir);
}//if handle

sort($list);
reset($list);
return $list;
} //func

 

Navigation:

[Reply to this 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

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