WP_Filesystem_FTPext::dirlist

Advertisement

Summery Summery

Gets details for files in a directory or a specific file.

Syntax Syntax

WP_Filesystem_FTPext::dirlist( string $path = '.', bool $include_hidden = true, bool $recursive = false )

Parameters Parameters

$path

(Optional) Path to directory or file.

Default value: '.'

$include_hidden

(Optional) Whether to include details of hidden ("." prefixed) files.

Default value: true

$recursive

(Optional) Whether to recursively include file details in nested directories.

Default value: false

Return Return

(array|false) Array of files. False if unable to list directory contents.

  • 'name'
    (string) Name of the file or directory.
  • 'perms'
    (string) *nix representation of permissions.
  • 'permsn'
    (int) Octal representation of permissions.
  • 'owner'
    (string) Owner name or ID.
  • 'size'
    (int) Size of file in bytes.
  • 'lastmodunix'
    (int) Last modified unix timestamp.
  • 'lastmod'
    (mixed) Last modified month (3 letter) and day (without leading 0).
  • 'time'
    (int) Last modified time.
  • 'type'
    (string) Type of resource. 'f' for file, 'd' for directory.
  • 'files'
    (mixed) If a directory and $recursive is true, contains another array of files.

Source Source

File: wp-admin/includes/class-wp-filesystem-ftpext.php

				}
			}
		}

		// Replace symlinks formatted as "source -> target" with just the source name.
		if ( isset( $b['islink'] ) && $b['islink'] ) {
			$b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] );
		}

		return $b;
	}

	/**
	 * Gets details for files in a directory or a specific file.
	 *
	 * @since 2.5.0
	 *
	 * @param string $path           Path to directory or file.
	 * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
	 *                               Default true.
	 * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
	 *                               Default false.
	 * @return array|false {
	 *     Array of files. False if unable to list directory contents.
	 *
	 *     @type string $name        Name of the file or directory.
	 *     @type string $perms       *nix representation of permissions.
	 *     @type int    $permsn      Octal representation of permissions.
	 *     @type string $owner       Owner name or ID.
	 *     @type int    $size        Size of file in bytes.
	 *     @type int    $lastmodunix Last modified unix timestamp.
	 *     @type mixed  $lastmod     Last modified month (3 letter) and day (without leading 0).
	 *     @type int    $time        Last modified time.
	 *     @type string $type        Type of resource. 'f' for file, 'd' for directory.
	 *     @type mixed  $files       If a directory and $recursive is true, contains another array of files.
	 * }
	 */
	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;
		}

		$pwd = ftp_pwd( $this->link );

		if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist.
			return false;
		}

		$list = ftp_rawlist( $this->link, '-a', false );

		@ftp_chdir( $this->link, $pwd );

Advertisement

Changelog Changelog

Changelog
Version Description
2.5.0 Introduced.

Advertisement

Leave a Reply