遍历目录中的特定文件 [英] Iterate over specific files in a directory

查看:56
本文介绍了遍历目录中的特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用glob获取所有以"t_"开头的图像.我应该使用哪种模式来做到这一点?

I need to get all images that begin with "t_" using glob. What pattern should I use to do this?

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

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

推荐答案

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

这篇关于遍历目录中的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆