function &_getRecursiveFileList($directory, $file_test_function) { if(!is_dir($directory)) return array(); $dh = opendir($directory); $file_list = array(); while ($file = readdir($dh)) { $file_path = $directory . '/' . $file; if (0 === strpos($file, '.')) continue; if (is_dir($file_path)) { $file_list = array_merge($file_list, $this->_getRecursiveFileList( $file_path, $file_test_function)); } if ($file_test_function[0]->$file_test_function[1]($file)) { $file_list[] = Fs :: normalizePath($file_path); } } closedir($dh); sort($file_list); return $file_list; }
function testRecursiveFind() { $this->_createFileSystem(); $res = Fs :: recursiveFind(TEST_DIR_ABSOLUTE_PATH . '/tmp/', 'fd', '~test\d_1~'); sort($res); $this->assertEqual( $res, array( Fs :: normalizePath(TEST_DIR_ABSOLUTE_PATH . '/tmp/test1_1'), Fs :: normalizePath(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/hey/test3_1'), Fs :: normalizePath(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/test2_1'), ) ); $this->_removeFileSystem(); }
function walkDir($dir, $function_def, $params=array(), $include_first=false) { $return_params = array(); $separator = Fs :: separator(); $dir = Fs :: normalizePath($dir); $dir = Fs :: chop($dir); $params['separator'] = $separator; Fs :: _doWalkDir($dir, $separator, $function_def, $return_params, $params, $include_first); return $return_params; }