list_files
函数
list_files ( $folder = '', $levels = 100, $exclusions = array() )
- 参数
-
-
(string)
$folder
Optional. Full path to folder. Default empty.- Required: 否
- Default: (empty)
-
(int)
$levels
Optional. Levels of folders to follow, Default 100 (PHP Loop limit).- Required: 否
- Default: 100
-
(string[])
$exclusions
Optional. List of folders and files to skip.- Required: 否
- Default: array()
-
(string)
- 返回值
-
- (string[]|false) Array of files on success, false on failure.
- 定义位置
-
-
wp-admin/includes/file.php
, line 136
-
wp-admin/includes/file.php
- 引入
- 2.6.0
- 弃用
- –
Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep.
The depth of the recursiveness can be controlled by the $levels param.
function list_files( $folder = '', $levels = 100, $exclusions = array() ) { if ( empty( $folder ) ) { return false; } $folder = trailingslashit( $folder ); if ( ! $levels ) { return false; } $files = array(); $dir = @opendir( $folder ); if ( $dir ) { while ( ( $file = readdir( $dir ) ) !== false ) { // Skip current and parent folder links. if ( in_array( $file, array( '.', '..' ), true ) ) { continue; } // Skip hidden and excluded files. if ( '.' === $file[0] || in_array( $file, $exclusions, true ) ) { continue; } if ( is_dir( $folder . $file ) ) { $files2 = list_files( $folder . $file, $levels - 1 ); if ( $files2 ) { $files = array_merge( $files, $files2 ); } else { $files[] = $folder . $file . '/'; } } else { $files[] = $folder . $file; } } closedir( $dir ); } return $files; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。