note 103418 added to function.in-array

From: Date: Tue, 12 Apr 2011 09:04:17 +0000
Subject: note 103418 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-178740@lists.php.net to get a copy of this message
A function I created to non-recursively get the path of all files and folders including sub-directories of a given folder. Though I have not tested it completely, it seems to be working. <?php /** * Finds path, relative to the given root folder, of all files and directories in the given directory and its sub-directories non recursively. * Will return an array of the form * array( * 'files' => [], * 'dirs' => [], * ) * @author sreekumar * @param string $root * @result array */ function read_all_files($root = '.'){ $files = array('files'=>array(), 'dirs'=>array()); $directories = array(); $last_letter = $root[strlen($root)-1]; $root = ($last_letter == '\\' || $last_letter == '/') ? $root : $root.DIRECTORY_SEPARATOR; $directories[] = $root; while (sizeof($directories)) { $dir = array_pop($directories); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..') { continue; } $file = $dir.$file; if (is_dir($file)) { $directory_path = $file.DIRECTORY_SEPARATOR; array_push($directories, $directory_path); $files['dirs'][] = $directory_path; } elseif (is_file($file)) { $files['files'][] = $file; } } closedir($handle); } } return $files; } ---- Server IP: 69.147.83.197 Probable Submitter: 183.83.235.168 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/103418 Del: integrated -- https://master.php.net/note/delete/103418/integrated Del: useless -- https://master.php.net/note/delete/103418/useless Del: bad code -- https://master.php.net/note/delete/103418/bad+code Del: spam -- https://master.php.net/note/delete/103418/spam Del: non-english -- https://master.php.net/note/delete/103418/non-english Del: in docs -- https://master.php.net/note/delete/103418/in+docs Del: other reasons-- https://master.php.net/note/delete/103418 Reject -- https://master.php.net/note/reject/103418 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178740) next »