blob: 574a5d8b069402bcb74b76595afc55cbe892d7c7 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +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
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @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
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
26 */
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
Pascal Kriete98a447a2010-01-07 18:14:28 +000039 * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
Derek Allard2067d1a2008-11-13 22:59:24 +000040 * @return array
Barry Mienydd671972010-10-04 16:33:58 +020041 */
Derek Allard2067d1a2008-11-13 22:59:24 +000042if ( ! function_exists('directory_map'))
43{
Pascal Kriete98a447a2010-01-07 18:14:28 +000044 function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE)
45 {
Derek Allard2067d1a2008-11-13 22:59:24 +000046 if ($fp = @opendir($source_dir))
47 {
Pascal Kriete98a447a2010-01-07 18:14:28 +000048 $filedata = array();
49 $new_depth = $directory_depth - 1;
Barry Mienydd671972010-10-04 16:33:58 +020050 $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
51
Derek Allard2067d1a2008-11-13 22:59:24 +000052 while (FALSE !== ($file = readdir($fp)))
53 {
Pascal Kriete98a447a2010-01-07 18:14:28 +000054 // Remove '.', '..', and hidden files [optional]
55 if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.'))
Derek Allard2067d1a2008-11-13 22:59:24 +000056 {
57 continue;
58 }
Pascal Kriete98a447a2010-01-07 18:14:28 +000059
60 if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file))
Derek Allard2067d1a2008-11-13 22:59:24 +000061 {
Pascal Kriete98a447a2010-01-07 18:14:28 +000062 $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden);
Derek Allard2067d1a2008-11-13 22:59:24 +000063 }
64 else
65 {
66 $filedata[] = $file;
67 }
68 }
Barry Mienydd671972010-10-04 16:33:58 +020069
Derek Allard2067d1a2008-11-13 22:59:24 +000070 closedir($fp);
71 return $filedata;
72 }
Pascal Kriete98a447a2010-01-07 18:14:28 +000073
74 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000075 }
76}
77
78
79/* End of file directory_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +000080/* Location: ./system/helpers/directory_helper.php */