如上:
譬如Linux中 文件所在目录:
log@oldlog:/www/bookman/class/copyright_zip/00000000002> 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 00000000002-all.txt P-00000000002-02.jpg B-00000000002.zip请各位注意:1、上述 数字+.txt 的是我要统计的 其中每一个 纯数字+.txt 算一章,我的目的是统计这个目录下有几个章节! 2、我目前有想法 就是找到/www/bookman/class/copyright_zip/00000000002这个目录下 最大的数字+.txt 并且取其数字部分 就是我所要统计的总共有多少章了。 现求代码!!!!
譬如Linux中 文件所在目录:
log@oldlog:/www/bookman/class/copyright_zip/00000000002> 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 00000000002-all.txt P-00000000002-02.jpg B-00000000002.zip请各位注意:1、上述 数字+.txt 的是我要统计的 其中每一个 纯数字+.txt 算一章,我的目的是统计这个目录下有几个章节! 2、我目前有想法 就是找到/www/bookman/class/copyright_zip/00000000002这个目录下 最大的数字+.txt 并且取其数字部分 就是我所要统计的总共有多少章了。 现求代码!!!!
$count = preg_match_all('/(?:^|\s)\d+\.txt(?:\s|$)/im','1.txt 2.txt 3.txt 4.txt 5.txt 6.txt7.txt 8.txt 00000000002-all.txt P-00000000002-02.jpgB-00000000002.zip',$m);
echo print_r($m,1)."<br/>";
echo $count;
foreach (glob($dir . '/*.txt') as $txtFile) {
$fileName = basename($txtFile);
$fileNameInfo = explode('.', $fileName); $max = $max>(int)$fileNameInfo[0] ? $max : (int)$fileNameInfo[0];
}// now , $max is your what you expected.
----------------------------------------
指点迷津网 http://www.zhidianmijin.com
linux指令:log@oldlog:/www/bookman/class/copyright_zip/00000000002>ls -v [1-9]*.txt | wc -l
下面是我的答案。
find . -name [1-9]*.txt -print
不知道我的正则写的对不对,我没试验,仅供参考。
function foo($v) {
return ereg('^[0-9]+\.', $v);
}
$ar = array_filter(glob("$dir/*.txt"), 'foo');print_r($ar);