Gets details for files in a directory or a specific file.
Parameters
$path
stringrequired- Path to directory or file.
$include_hidden
booloptional- Whether to include details of hidden ("." prefixed) files.
Default:
true
$recursive
booloptional- Whether to recursively include file details in nested directories.
Default:
false
Return
array|false Array of arrays containing file information. False if unable to list directory contents....$0
arrayArray of file information. Note that some elements may not be available on all filesystems.name
stringName of the file or directory.perms
string*nix representation of permissions.permsn
stringOctal representation of permissions.number
falseFile number. Always false in this context.owner
string|falseOwner name or ID, or false if not available.group
string|falseFile permissions group, or false if not available.size
int|string|falseSize of file in bytes. May be a numeric string.
False if not available.lastmodunix
int|string|falseLast modified unix timestamp. May be a numeric string.
False if not available.lastmod
string|falseLast modified month (3 letters) and day (without leading 0), or false if not available.time
string|falseLast modified time, or false if not available.type
stringType of resource.'f'
for file,'d'
for directory,'l'
for link.files
array|falseIf a directory and$recursive
is true, contains another array of files. False if unable to list directory contents.
Source
public function dirlist( $path, $include_hidden = true, $recursive = false ) { if ( $this->is_file( $path ) ) { $limit_file = basename( $path ); $path = dirname( $path ); } else { $limit_file = false; } if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) { return false; } $dir = dir( $path ); if ( ! $dir ) { return false; } $path = trailingslashit( $path ); $ret = array(); while ( false !== ( $entry = $dir->read() ) ) { $struc = array(); $struc['name'] = $entry; if ( '.' === $struc['name'] || '..' === $struc['name'] ) { continue; } if ( ! $include_hidden && '.' === $struc['name'][0] ) { continue; } if ( $limit_file && $struc['name'] !== $limit_file ) { continue; } $struc['perms'] = $this->gethchmod( $path . $entry ); $struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] ); $struc['number'] = false; $struc['owner'] = $this->owner( $path . $entry ); $struc['group'] = $this->group( $path . $entry ); $struc['size'] = $this->size( $path . $entry ); $struc['lastmodunix'] = $this->mtime( $path . $entry ); $struc['lastmod'] = gmdate( 'M j', $struc['lastmodunix'] ); $struc['time'] = gmdate( 'h:i:s', $struc['lastmodunix'] ); $struc['type'] = $this->is_dir( $path . $entry ) ? 'd' : 'f'; if ( 'd' === $struc['type'] ) { if ( $recursive ) { $struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive ); } else { $struc['files'] = array(); } } $ret[ $struc['name'] ] = $struc; } $dir->close(); unset( $dir ); return $ret; }
Related
Show 4 moreShow lessUses Description WP_Filesystem_Direct::dirlist() wp-admin/includes/class-wp-filesystem-direct.php
Gets details for files in a directory or a specific file.
WP_Filesystem_Direct::is_file() wp-admin/includes/class-wp-filesystem-direct.php
Checks if resource is a file.
WP_Filesystem_Direct::is_dir() wp-admin/includes/class-wp-filesystem-direct.php
Checks if resource is a directory.
WP_Filesystem_Direct::is_readable() wp-admin/includes/class-wp-filesystem-direct.php
Checks if a file is readable.
WP_Filesystem_Direct::owner() wp-admin/includes/class-wp-filesystem-direct.php
Gets the file owner.
WP_Filesystem_Direct::group() wp-admin/includes/class-wp-filesystem-direct.php
Gets the file’s group.
WP_Filesystem_Direct::size() wp-admin/includes/class-wp-filesystem-direct.php
Gets the file size (in bytes).
WP_Filesystem_Direct::mtime() wp-admin/includes/class-wp-filesystem-direct.php
Gets the file modification time.
trailingslashit() wp-includes/formatting.php
Appends a trailing slash.
Used by Description WP_Filesystem_Direct::dirlist() wp-admin/includes/class-wp-filesystem-direct.php
Gets details for files in a directory or a specific file.
WP_Filesystem_Direct::delete() wp-admin/includes/class-wp-filesystem-direct.php
Deletes a file or directory.
WP_Filesystem_Direct::chgrp() wp-admin/includes/class-wp-filesystem-direct.php
Changes the file group.
WP_Filesystem_Direct::chmod() wp-admin/includes/class-wp-filesystem-direct.php
Changes filesystem permissions.
WP_Filesystem_Direct::chown() wp-admin/includes/class-wp-filesystem-direct.php
Changes the owner of a file or directory.
Changelog
Version Description 2.5.0 Introduced.
User Contributed Notes
You must log in before being able to contribute a note or feedback.