从scandir中排除隐藏文件 [英] Exclude hidden files from scandir

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

问题描述

我正在使用以下代码来获取目录中的图像列表:

I am using the following code to get a list of images in a directory:

$files = scandir($imagepath);

$files也包括隐藏文件.如何排除它们?

but $files also includes hidden files. How can I exclude them?

推荐答案

在Unix上,您可以使用 preg_grep 过滤掉以点开头的文件名:

On Unix, you can use preg_grep to filter out filenames that start with a dot:

$files = preg_grep('/^([^.])/', scandir($imagepath));

这篇关于从scandir中排除隐藏文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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