source: trunk/www.guidonia.net/wp/wp-content/themes/atahualpa/functions/bfa_m_find_in_dir.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 1.6 KB
Line 
1<?php
2function m_find_in_dir( $root, $pattern, $recursive = true, $case_sensitive = false ) {
3 $result = array();
4 if( $case_sensitive ) {
5 if( false === m_find_in_dir__( $root, $pattern, $recursive, $result )) {
6 return false;
7 }
8 } else {
9 if( false === m_find_in_dir_i__( $root, $pattern, $recursive, $result )) {
10 return false;
11 }
12 }
13
14 return $result;
15}
16
17/**
18 * @access private
19 */
20function m_find_in_dir__( $root, $pattern, $recursive, &$result ) {
21 $dh = @opendir( $root );
22 if( false === $dh ) {
23 return false;
24 }
25 while( $file = readdir( $dh )) {
26 if( "." == $file || ".." == $file ){
27 continue;
28 }
29 if( false !== @ereg( $pattern, "{$root}/{$file}" )) {
30 $result[] = "{$root}/{$file}";
31 }
32 if( false !== $recursive && is_dir( "{$root}/{$file}" )) {
33 m_find_in_dir__( "{$root}/{$file}", $pattern, $recursive, $result );
34 }
35 }
36 closedir( $dh );
37 return true;
38}
39
40/**
41 * @access private
42 */
43function m_find_in_dir_i__( $root, $pattern, $recursive, &$result ) {
44 $dh = @opendir( $root );
45 if( false === $dh ) {
46 return false;
47 }
48 while( $file = readdir( $dh )) {
49 if( "." == $file || ".." == $file ){
50 continue;
51 }
52 if( false !== @eregi( $pattern, "{$root}/{$file}" )) {
53 $result[] = "{$root}/{$file}";
54 }
55 if( false !== $recursive && is_dir( "{$root}/{$file}" )) {
56 m_find_in_dir__( "{$root}/{$file}", $pattern, $recursive, $result );
57 }
58 }
59 closedir( $dh );
60 return true;
61}
62?>
Note: See TracBrowser for help on using the repository browser.