在目录中查找文件 [英] finding files in a dir

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

问题描述

我有一个目录里面有很多文件:

I have a directory with a lot of files inside:

pic_1_79879879879879879.jpg
pic_1_89798798789798789.jpg
pic_1_45646545646545646.jpg
pic_2_12345678213145646.jpg
pic_3_78974565646465645.jpg
etc...

我只需要列出pic_1_文件。任何想法我该怎么办?
提前感谢

I need to list only the pic_1_ files. Any idea how I can do? Thanks in advance.

推荐答案

开启dir功能将帮助您

The opend dir function will help you

$dir ="your path here";

$filetoread ="pic_1_";
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
               if (strpos($file,$filetoread) !== false)
                echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
            }
            closedir($dh);
        }
    }

祝你好运见php.net opendir

good luck see php.net opendir

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

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