Re: Getting the filenames from a folder
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Getting the filenames from a folder

From: juglesh <jugleshjunk@hotmail.com>
Date: Mon Oct 31 2005 - 03:57:10 CET

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
Received on Mon Nov 21 02:53:17 2005