Write a function to traverse all files and subfolders in a folder.

Source: Internet
Author: User
: This article mainly introduces (the clearest) writing a function that can traverse all files and subfolders in a folder ., If you are interested in the PHP Tutorial, refer.
 
\n" . htmlspecialchars(print_r($vars, true)) . "\n

\n";echo " {$content}"; return;}

Opendir -- open the directory handle
Description
Resource opendir (string path)
Returns a directory handle that can be later used in closedir (), readdir (), and rewinddir () calls.
If path is not a valid directory or cannot be opened due to permission restrictions or file system errors, opendir () returns FALSE and generates an E_WARNING-level PHP error message. You can add the "@" symbol before opendir () to suppress the output of error messages.
Readdir -- read entries from the directory handle
Description
String readdir (resource dir_handle)
Returns the file name of the next file in the directory. File names are returned in the order in the file system.
Check the style of readdir () returned values in the following example. We explicitly test whether the returned values are all equal to (both values and types are the same-for more information, see Comparison operators) FALSE, otherwise, if the name of any directory item is evaluated as FALSE, the loop will be stopped (for example, a directory named "0 ").
Is_dir -- determine whether the specified file name is a directory
Description
Bool is_dir (string filename)
Returns TRUE if the file name exists and is a directory. If filename is a relative path, check its relative path according to the current working directory.
Note: the result of this function is cached. For more information, see clearstatcache ().
Note: This function cannot act on remote files. the checked files must be accessed through the file system on the server.
Scandir -- list files and directories in a specified path
Description
Array scandir (string directory [, int sorting_order])
Returns an array containing files and directories in directory. If directory is not a directory, a Boolean value of FALSE is returned, and an E_WARNING-level error is generated.

By default, return values are listed alphabetically in ascending order. If the optional parameter sorting_order (set to 1) is used, it is sorted alphabetically in descending order.

The above introduces (the most explicit) writing a function that can traverse all the files and subfolders in a folder ., Including some content, hope to be helpful to friends who are interested in PHP tutorials.

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.