本文整理汇总了PHP中filesystem::is_dir方法的典型用法代码示例。如果您正苦于以下问题:PHP filesystem::is_dir方法的具体用法?PHP filesystem::is_dir怎么用?PHP filesystem::is_dir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类filesystem
的用法示例。
在下文中一共展示了filesystem::is_dir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search_files
/**
* @en Find files
* @ru Поиск файлов
*
* # listing all the files in a directory and subdirectories:
*
* $result = filesystem::scandir('./src/lib/'); # Array
* # (
* # [0] => src/lib/include.php
* # [1] => src/lib/README.md
* # [2] => src/lib/src/etc/rude-system.php
* # [3] => src/lib/src/etc/rude-globals.php
* # [4] => src/lib/src/etc/rude-measures.php
* # [5] => src/lib/src/etc/rude-visitor.php
* # [6] => src/lib/src/etc/rude-date.php
* # [7] => src/lib/src/etc/rude-url.php
* # [8] => src/lib/src/etc/rude-html.php
* # [9] => src/lib/src/etc/rude-crypt.php
* # [10] => src/lib/src/etc/rude-cookies.php
* # [11] => src/lib/src/etc/rude-math.php
* # [12] => src/lib/src/etc/rude-autoload.php
* # [13] => src/lib/src/etc/rude-headers.php
* # [14] => src/lib/src/etc/rude-speedtest.php
* # [15] => src/lib/src/etc/rude-curl.php
* # [16] => src/lib/src/etc/rude-filesystem.php
* # [17] => src/lib/src/etc/rude-session.php
* #
* # ... and 164 files more
* # )
*
*
* # listing all the files in a directory and subdirectories with '.md' file extension:
*
* $result = filesystem::scandir('src/lib', 'md'); # Array
* # (
* # [0] => src/lib/README.md
* # [1] => src/lib/LICENSE.md
* # [2] => src/lib/NOTICE.md
* # )
*
*
* # listing all the files in a directory but not in subdirectories with '.php' file extension:
*
* $result = filesystem::search_files('src/lib', 'php', false); # Array
* # (
* # [0] => include.php
* # )
*
*
*
* @param string $path
* @param string $extension
* @param bool $recursively Set 'true' if you need to gather files from subdirectories
*
* @return array
*/
public static function search_files($path, $extension = null, $recursively = true)
{
$file_list = null;
if ($recursively === true) {
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
$file_list[] = $name;
}
} else {
$file_list = scandir($path);
}
$result = array();
if ($file_list) {
foreach ($file_list as $file_path) {
if (filesystem::is_dir($file_path)) {
continue;
# exclude directories
}
if ($extension === null) {
$result[] = $file_path;
continue;
}
if (filesystem::file_extension($file_path) == $extension) {
$result[] = $file_path;
}
}
}
return $result;
}