Open In App

PHP | FilesystemIterator setFlags() Function

Last Updated : 26 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The FilesystemIterator::setFlags() function is an inbuilt function in PHP which is used to set the handling flags.

Syntax:

void FilesystemIterator::setFlags( int $flags )

Parameters: This function accepts single parameter $flags which holds the handling flags to set.

Return Value: This function does not return any value.

Below programs illustrate the FilesystemIterator::setFlags() function in PHP:

Program 1:




<?php
  
// Create new file system iterator
$fileItr = new FilesystemIterator(__DIR__, 
    FilesystemIterator::CURRENT_AS_PATHNAME);
  
// Set the flags
$fileItr->setFlags(FilesystemIterator::KEY_AS_FILENAME);
  
// Get the flag 
$flag = $fileItr->getFlags(); 
    
// Display the flag 
var_dump($flag); 
  
?>


Output:

int(256)

Program 2:




<?php
  
// Create new file system iterator
$fileItr = new FilesystemIterator(__DIR__, 
    FilesystemIterator::CURRENT_AS_PATHNAME);
  
// Set the flag
$fileItr->setFlags(FilesystemIterator::CURRENT_AS_SELF);
  
// Get the flag 
$flag = $fileItr->getFlags(); 
    
// Display the flag 
var_dump($flag); 
  
?>


Output:

int(16)

Reference: https://www.php.net/manual/en/filesystemiterator.setflags.php



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads