迭代目录中的特定文件

时间:2010-06-26 04:22:27

标签: php regex glob

我需要使用glob获取所有以“t_”开头的图像。我应该用什么模式来做这件事?

        //get any image files that begin with "t_" -- (t_image.jpg) not (image.jpg)
        $images = glob("" . $dir . "*.jpg");

        foreach($images as $image)
        {
            echo $image;
        }

1 个答案:

答案 0 :(得分:4)

foreach (glob("t_*.jpg") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}

这意味着:

foreach (glob("$dir/t_*.jpg") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}

另见:

http://ca2.php.net/manual/en/function.glob.php