yii2helperfile-find

Yii2: Finding file and getting path in a directory tree


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.

Anyone who knows another Yii2 helper to accomplish this?


Solution

  • You should simply try:

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

    Read more here.