Issue Feature Closed

#93209Add getFile() to TYPO3\CMS\Core\Resource\Folder

Ingo Reuter 01/03/21, 22:59 updated 05/04/21, 08:04

Description

Working with Files and Folders in FAL is quite convenient. The class TYPO3\CMS\Core\Resource\Folder offers many methods for getting folders and files inside a specific folder.

The class allows to retrieve a list of all files inside a folder, a list of subfolders, to create a new file inside the folder and many more. It is even possible to get a specific folder inside the current folder (via $folder->getSubfolder("folderName")). Unfortunately the equivalent method does not exist for files. It would be handy to have something like $folder->getFile("filename.ext") instead of calling $folder->getStorage()->getFileInFolder("filename.ext", $folder). It might be mentioned, that the method hasFile(..) is already implemented.

My suggestion is to add the following method to TYPO3\CMS\Core\Resource\Folder

public function getFile($fileName) {
    if (!$this->storage->hasFileInFolder($fileName, $this)) {
            throw new \InvalidArgumentException('File "' . $fileName . '" does not exist in "' . $this->identifier . '"', 1609714577);
    }
    return $this->storage->getFileInFolder($fileName, $this);
}

Reviews 1