PHP
SPL/Iterators

FilesystemIterator::setFlags

FilesystemIterator::setFlags

(PHP 5 >= 5.3.0, PHP 7)

FilesystemIterator::setFlags — Sets handling flags

Description

public void FilesystemIterator::setFlags ([ int $flags ] )

Sets handling flags.

Parameters

flags

The handling flags to set. See the FilesystemIterator constants.

Return Values

No value is returned.

Examples

Example #1 FilesystemIterator::key() example

This example demonstrates the difference between the FilesystemIterator::KEY_AS_PATHNAME and FilesystemIterator::KEY_AS_FILENAME flags.

<?php $iterator = new FilesystemIterator(dirname(__FILE__), FilesystemIterator::KEY_AS_PATHNAME echo "Key as Pathname:\n"; foreach ($iterator as $key => $fileinfo) {     echo $key . "\n"; } $iterator->setFlags(FilesystemIterator::KEY_AS_FILENAME echo "\nKey as Filename:\n"; foreach ($iterator as $key => $fileinfo) {     echo $key . "\n"; } ?>

The above example will output something similar to:

Key as Pathname: /www/examples/apple.jpg /www/examples/banana.jpg /www/examples/example.php Key as Filename: apple.jpg banana.jpg example.php

See Also

  • FilesystemIterator::__construct() - Constructs a new filesystem iterator

  • FilesystemIterator::getFlags() - Get the handling flags

← FilesystemIterator::rewind

FilterIterator →

© 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

https://secure.php.net/manual/en/filesystemiterator.setflags.php