function FileSystemInterface::scanDirectory
Same name in other branches
- 9 core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::scanDirectory()
- 10 core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::scanDirectory()
- 11.x core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::scanDirectory()
Finds all files that match a given mask in a given directory.
Directories and files beginning with a dot are excluded; this prevents hidden files and directories (such as SVN working directories) from being scanned. Use the umask option to skip configuration directories to eliminate the possibility of accidentally exposing configuration information. Also, you can use the base directory, recurse, and min_depth options to improve performance by limiting how much of the filesystem has to be traversed.
Parameters
string $dir: The base directory or URI to scan, without trailing slash.
string $mask: The preg_match() regular expression for files to be included.
array $options: An associative array of additional options, with the following elements:
- 'nomask': The preg_match() regular expression for files to be excluded. Defaults to the 'file_scan_ignore_directories' setting.
- 'callback': The callback function to call for each match. There is no default callback.
- 'recurse': When TRUE, the directory scan will recurse the entire tree starting at the provided directory. Defaults to TRUE.
- 'key': The key to be used for the returned associative array of files. Possible values are 'uri', for the file's URI; 'filename', for the basename of the file; and 'name' for the name of the file without the extension. Defaults to 'uri'.
- 'min_depth': Minimum depth of directories to return files from. Defaults to 0.
Return value
array An associative array (keyed on the chosen key) of objects with 'uri', 'filename', and 'name' properties corresponding to the matched files.
Throws
\Drupal\Core\File\Exception\NotRegularDirectoryException If the directory does not exist.
1 method overrides FileSystemInterface::scanDirectory()
- FileSystem::scanDirectory in core/
lib/ Drupal/ Core/ File/ FileSystem.php - Finds all files that match a given mask in a given directory.
File
-
core/
lib/ Drupal/ Core/ File/ FileSystemInterface.php, line 526
Class
- FileSystemInterface
- Provides an interface for helpers that operate on files and stream wrappers.
Namespace
Drupal\Core\FileCode
public function scanDirectory($dir, $mask, array $options = []);
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.