如上:
譬如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 并且取其数字部分 就是我所要统计的总共有多少章了。 现求代码!!!!

解决方案 »

  1.   


    $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;
      

  2.   

    $dir = '/www/bookman/class/copyright_zip/00000000002';$max = 0;
    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
      

  3.   

    不好意思这位老大 我可能没描述好 我的 数字+.txt 是无限多个 我要从中取最大的数字的值 来作为总共有多少章!!!在下想出个办法 请各位点解 是否还有其他好的方法:
    linux指令:log@oldlog:/www/bookman/class/copyright_zip/00000000002>ls -v [1-9]*.txt | wc -l
      

  4.   

    我认为你写的对。
    下面是我的答案。
    find . -name [1-9]*.txt -print
    不知道我的正则写的对不对,我没试验,仅供参考。
      

  5.   

    $dir = '/www/bookman/class/copyright_zip/00000000002';
    function foo($v) {
      return ereg('^[0-9]+\.', $v);
    }
    $ar = array_filter(glob("$dir/*.txt"), 'foo');print_r($ar);