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; } $ret = array(); $dir = dir( $this->sftp_path( $path ) ); if ( ! $dir ) { return false; } $path = trailingslashit( $path ); while ( false !== ( $entry = $dir->read() ) ) { $struc = array(); $struc['name'] = $entry; if ( '.' === $struc['name'] || '..' === $struc['name'] ) { continue; // Do not care about these folders. } 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 5 moreShow lessUses Description WP_Filesystem_SSH2::sftp_path() wp-admin/includes/class-wp-filesystem-ssh2.php
Gets the ssh2.sftp PHP stream wrapper path to open for the given file.
WP_Filesystem_SSH2::is_file() wp-admin/includes/class-wp-filesystem-ssh2.php
Checks if resource is a file.
WP_Filesystem_SSH2::is_dir() wp-admin/includes/class-wp-filesystem-ssh2.php
Checks if resource is a directory.
WP_Filesystem_SSH2::is_readable() wp-admin/includes/class-wp-filesystem-ssh2.php
Checks if a file is readable.
WP_Filesystem_SSH2::size() wp-admin/includes/class-wp-filesystem-ssh2.php
Gets the file size (in bytes).
WP_Filesystem_SSH2::mtime() wp-admin/includes/class-wp-filesystem-ssh2.php
Gets the file modification time.
WP_Filesystem_SSH2::dirlist() wp-admin/includes/class-wp-filesystem-ssh2.php
Gets details for files in a directory or a specific file.
WP_Filesystem_SSH2::owner() wp-admin/includes/class-wp-filesystem-ssh2.php
Gets the file owner.
WP_Filesystem_SSH2::group() wp-admin/includes/class-wp-filesystem-ssh2.php
Gets the file’s group.
trailingslashit() wp-includes/formatting.php
Appends a trailing slash.
Used by Description WP_Filesystem_SSH2::dirlist() wp-admin/includes/class-wp-filesystem-ssh2.php
Gets details for files in a directory or a specific file.
WP_Filesystem_SSH2::delete() wp-admin/includes/class-wp-filesystem-ssh2.php
Deletes a file or directory.
Changelog
Version Description 2.7.0 Introduced.
User Contributed Notes
You must log in before being able to contribute a note or feedback.