note 29329 deleted from function.opendir by didou

From: Date: Thu, 29 May 2003 22:27:56 +0000
Subject: note 29329 deleted from function.opendir by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-49358@lists.php.net to get a copy of this message
Note Submitter: Artistan@hotmail.com ---- Read files in folder and all sub folders. Newbie, message me with your thoughts on this............................... tried code from all over until i got it to do what i wanted function getfilesall($foldername) Stores files in an array including files in all subfolders given the folder name function getfilesone($foldername) Stores files ina an array from given folder name. checks if folder or not with if(!strchr($fil[$x],".")){.........} //files.php <?php //----------------------------------------------- // USER CONFIGURABLE ELEMENTS //----------------------------------------------- // Root path $root_path = "./"; //----------------------------------------------- require $root_path."filesfunction.php"; //------------------------------------------------ //getfilesall('images'); //Test //given a folder name, gets all filenames within the folder and subfolders //------------------------------------------------ function getfilesall($foldername) { $folder = "$foldername\\"; // fill an array with all items from a directory $arrayfiles = readfolderfiles($folder); //gets all subfolder info $filesarray = nextfolder($arrayfiles, $folder); //echo "Check This Out."; $result = count((array)$filesarray); //echo " $result <BR>"; //print_r($filesarray); //echo "<BR>"; return $filesarray; } //------------------------------------------------ //getfilesone('images'); //Test //given a folder name, gets all filenames within that folder //------------------------------------------------ function getfilesone($foldername) { $folder = "$foldername\\"; // fill an array with all items from a directory $arrayfiles = readfolderfiles($folder); //echo "Check This Out."; //$result = count((array)$arrayfiles); //echo " $result <BR>"; //print_r($arrayfiles); //echo "<BR>"; return $arrayfiles; } ?> //filefunctions.php <?php //********************************************* //User Function //function to read folder files and return them in an array function readfolderfiles($folder) { // fill an array with all items from a directory $handle = opendir($folder); while ($file = readdir($handle)) { $files[] = $folder.$file; } closedir($handle); $result = count($files); //echo "$result <BR>"; sort($files); //print_r($files); //echo "<BR>"; return $files; } function nextfolder($fil,$folder2) { //* $storefiles = (array)$fil; $result = count($fil); $x = 0; while($x <= $result-1) { //echo "$fil[$x] <BR>"; if(!strchr($fil[$x],".")) { $nextfolder = "{$fil[$x]}\\"; //echo($nextfolder); $Xfiles = readfolderfiles($nextfolder); $storefiles = array_merge($storefiles, $Xfiles); } $x = $x + 1; } $fil = array_merge($fil, $storefiles); return $fil; //*/ } ?>

« previous php.notes (#49358) next »