Yii2:在目录树中查找文件并获取路径 [英] Yii2: Finding file and getting path in a directory tree

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

问题描述

我正在尝试在一堆目录中搜索单个文件名并返回其路径.我以为FileHelper::findFiles()将是一个帮手,但似乎它不接受要搜索的文件名,而只是接受特定的根目录,然后返回找到的文件名数组.

I'm trying to search for a single filename in a bunch of directories and returning its path. I thought FileHelper::findFiles() would be a helping hand but it seems it doesn't accept a filename to search for but just a particular root directory and then it returns an array of found filenames.

认识另外一个Yii2帮助者的人吗?

Anyone who knows another Yii2 helper to accomplish this?

推荐答案

您应该尝试:

$files = yii\helpers\FileHelper::findFiles('/path', [
    'only' => ['filename.ext'],
    'recursive' => true,
]);

此处中了解更多.

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

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