php获取文件子目录,PHP获取文件列表,包括子目录

此函数支持GLOB_BRACE:

function rglob($pattern_in, $flags = 0) {

$patterns = array ();

if ($flags & GLOB_BRACE) {

$matches;

if (preg_match_all ( '#\{[^.\}]*\}#i', $pattern_in, $matches )) {

// Get all GLOB_BRACE entries.

$brace_entries = array ();

foreach ( $matches [0] as $index => $match ) {

$brace_entries [$index] = explode ( ',', substr ( $match, 1, - 1 ) );

}

// Create cartesian product.

// @source: https://stackoverflow.com/questions/6311779/finding-cartesian-product-with-php-associative-arrays

$cart = array (

array ()

);

foreach ( $brace_entries as $key => $values ) {

$append = array ();

foreach ( $cart as $product ) {

foreach ( $values as $item ) {

$product [$key] = $item;

$append [] = $product;

}

}

$cart = $append;

}

// Create multiple glob patterns based on the cartesian product.

foreach ( $cart as $vals ) {

$c_pattern = $pattern_in;

foreach ( $vals as $index => $val ) {

$c_pattern = preg_replace ( '/' . $matches [0] [$index] . '/', $val, $c_pattern, 1 );

}

$patterns [] = $c_pattern;

}

} else

$patterns [] = $pattern_in;

} else

$patterns [] = $pattern_in;

// @source: http://php.net/manual/en/function.glob.php#106595

$result = array ();

foreach ( $patterns as $pattern ) {

$files = glob ( $pattern, $flags );

foreach ( glob ( dirname ( $pattern ) . '/*', GLOB_ONLYDIR | GLOB_NOSORT ) as $dir ) {

$files = array_merge ( $files, rglob ( $dir . '/' . basename ( $pattern ), $flags ) );

}

$result = array_merge ( $result, $files );

}

return $result;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值