Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



list_files ›

Seit2.6.0
Veraltetn/v
list_files ( $folder = '', $levels = 100 )
Parameter: (2)
  • (string) $folder Optional. Full path to folder. Default empty.
    Erforderlich: Nein
    Standard: (leer)
  • (int) $levels Optional. Levels of folders to follow, Default 100 (PHP Loop limit).
    Erforderlich: Nein
    Standard: 100
Gibt zurück:
  • (bool|array) False on failure, Else array of files
Definiert in:
Codex:

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.



Quellcode

function list_files( $folder = '', $levels = 100 ) {
	if ( empty($folder) )
		return false;

	if ( ! $levels )
		return false;

	$files = array();
	if ( $dir = @opendir( $folder ) ) {
		while (($file = readdir( $dir ) ) !== false ) {
			if ( in_array($file, array('.', '..') ) )
				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;
}