【发布时间】:2010-05-18 23:17:24
【问题描述】:
在我问之前我搜索过,没有运气..
我正在为自己寻找一个简单的脚本,我可以搜索文件/文件夹。在php手册中找到了这个代码sn-p(我想我需要这个),但它不适合我。
“正在寻找一种使用掩码搜索文件/目录的简单方法。这是这样的功能。
默认情况下,此函数会将scandir()结果保存在内存中,以避免多次扫描同一目录。"
<?php
function sdir( $path='.', $mask='*', $nocache=0 ){
static $dir = array(); // cache result in memory
if ( !isset($dir[$path]) || $nocache) {
$dir[$path] = scandir($path);
}
foreach ($dir[$path] as $i=>$entry) {
if ($entry!='.' && $entry!='..' && fnmatch($mask, $entry) ) {
$sdir[] = $entry;
}
}
return ($sdir);
}
?>
感谢您的帮助,
彼得
【问题讨论】:
标签: php