(PHP 5 >= 5.3.0, PHP 7, PHP 8)
FilesystemIterator::setFlags — 设置处理标志
不返回值。
示例 #1 FilesystemIterator::key() 示例
此示例演示了 FilesystemIterator::KEY_AS_PATHNAME 和 FilesystemIterator::KEY_AS_FILENAME 标志之间的区别。
<?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";
}
?>
PHP 8.2 中以上示例的输出类似于
Key as Pathname: /www/examples/. /www/examples/.. /www/examples/apple.jpg /www/examples/banana.jpg /www/examples/example.php Key as Filename: . .. apple.jpg banana.jpg example.php