Opendir, readdir, and closedir (PHP operation directory and file)

Source: Internet
Author: User
The code is as follows: Copy code

$ Dir = "d: www.111cn.net ";

// Open the directory $ dir and assign the directory handle to the variable $ dh
If ($ dh = opendir ($ dir ))
{
// Get the file name through the while loop using the readdir function
While ($ file_name = readdir ($ dh ))! = False)
    {
Echo "file name:". $ file_name;
Echo "<br/> ";
Echo "<br/> ";
    }
   
// After processing is complete, close the directory handle $ dh
Closedir ($ dh );
}

/*
Opendir definition and usage
The opendir () function opens a directory handle, which can be used by closedir (), readdir (), and rewinddir.

If the operation succeeds, the function returns a directory stream. Otherwise, false and an error are returned. You can add "@" before the function name to hide the error output.

Syntax
Opendir (path, context)


Readdir definition and usage
The readdir () function returns the entries in the directory handle opened by opendir.

If the call succeeds, the function returns a file name; otherwise, false.

Syntax
Readdir (dir_stream)

The closedir () function disables the directory handle opened by the opendir () function.

Syntax
Closedir (dir_stream)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.