blob: 5a23944cb914ff0995dcfc1ab54a695c4ede98b3 [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter Directory Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Create a Directory Map
32 *
33 * Reads the specified directory and builds an array
34 * representation of it. Sub-folders contained with the
35 * directory will be mapped as well.
36 *
37 * @access public
38 * @param string path to source
39 * @param bool whether to limit the result to the top level only
40 * @return array
41 */
Derek Jones269b9422008-01-28 21:00:20 +000042if (! function_exists('directory_map'))
43{
44 function directory_map($source_dir, $top_level_only = FALSE)
45 {
46 if ($fp = @opendir($source_dir))
Derek Allardd2df9bc2007-04-15 17:41:17 +000047 {
Derek Jones269b9422008-01-28 21:00:20 +000048 $filedata = array();
49 while (FALSE !== ($file = readdir($fp)))
Derek Allardd2df9bc2007-04-15 17:41:17 +000050 {
Derek Jones269b9422008-01-28 21:00:20 +000051 if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)
52 {
53 $temp_array = array();
Derek Allardd2df9bc2007-04-15 17:41:17 +000054
Derek Jones269b9422008-01-28 21:00:20 +000055 $temp_array = directory_map($source_dir.$file."/");
Derek Allardd2df9bc2007-04-15 17:41:17 +000056
Derek Jones269b9422008-01-28 21:00:20 +000057 $filedata[$file] = $temp_array;
58 }
59 elseif (substr($file, 0, 1) != ".")
60 {
61 $filedata[] = $file;
62 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000063 }
Derek Jones269b9422008-01-28 21:00:20 +000064 return $filedata;
Derek Allardd2df9bc2007-04-15 17:41:17 +000065 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000066 }
67}
68
adminb0dd10f2006-08-25 17:25:49 +000069?>