Searching for "closedir()"

Q:

Explain the working with directories using opendir(), readdirs(), closedir() along with examples.

Answer

Opendir():- It opens the directory. This function returns a directory stream on success and FALSE and an error on failure.


Syntax:


Opendir(directory, context)


Context is a set of options that can modify the behavior of a stream


Example: opens sample directory.


$dir = opendir("directory");


 


Readdir(): It returns an entry from a directory handle opened by opendir().


Syntax:


Readdir(dir_stream)


Example:


$file = readdir($dir);


 


closedir(): It closes a directory handle opened by opendir().


Syntax:


closedir(dir_stream)


Example:


$file = close($dir);

Report Error

View answer Workspace Report Error Discuss

Subject: PHP