note 109140 added to function.scandir

From: Date: Fri, 22 Jun 2012 18:47:21 +0000
Subject: note 109140 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-188758@lists.php.net to get a copy of this message
<?php /** * Get an array that represents directory tree * @param string $directory Directory path * @param bool $recursive Include sub directories * @param bool $listDirs Include directories on listing * @param bool $listFiles Include files on listing * @param regex $exclude Exclude paths that matches this regex */ function directoryToArray($directory, $recursive = true, $listDirs = false, $listFiles = true, $exclude = '') { $arrayItems = array(); $skipByExclude = false; $handle = opendir($directory); if ($handle) { while (false !== ($file = readdir($handle))) { preg_match("/(^(([\.]){1,2})$|(\.(svn|git|md))|(Thumbs\.db|\.DS_STORE))$/iu", $file, $skip); if($exclude){ preg_match($exclude, $file, $skipByExclude); } if (!$skip && !$skipByExclude) { if (is_dir($directory. DIRECTORY_SEPARATOR . $file)) { if($recursive) { $arrayItems = array_merge($arrayItems, directoryToArray($directory. DIRECTORY_SEPARATOR . $file, $recursive, $listDirs, $listFiles, $exclude)); } if($listDirs){ $file = $directory . DIRECTORY_SEPARATOR . $file; $arrayItems[] = $file; } } else { if($listFiles){ $file = $directory . DIRECTORY_SEPARATOR . $file; $arrayItems[] = $file; } } } } closedir($handle); } return $arrayItems; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 189.60.29.200 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/109140 Del: integrated -- https://master.php.net/note/delete/109140/integrated Del: useless -- https://master.php.net/note/delete/109140/useless Del: bad code -- https://master.php.net/note/delete/109140/bad+code Del: spam -- https://master.php.net/note/delete/109140/spam Del: non-english -- https://master.php.net/note/delete/109140/non-english Del: in docs -- https://master.php.net/note/delete/109140/in+docs Del: other reasons-- https://master.php.net/note/delete/109140 Reject -- https://master.php.net/note/reject/109140 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188758) next »