PHP recursively traverses objects in a specified folder

Source: Internet
Author: User
The following small make up will bring you a PHP recursive traversal of files in a specified folder implementation method. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the file and folder chapter on the subway this morning. I just recently learned about the linux file system and thought that accessing file attributes is similar to Shell commands, so I want to practice it at night.

It seems that the php folder function does not provide the ability to traverse all files in the folder (including files in subdirectories), so you just want to implement one by yourself.

During writing, I found that some folder-related functions were not as intended. For example, dirname () obtains the path of the folder where the file is located based on the provided complete file path, but if you input a folder, it takes its parent folder. This must be understood. The same is true for basename (). the name of the folder is obtained by passing in the folder path. Neither of the two functions Returns '/' at the end of the result '/'

 '; $ Deep ++; // depth + 1 recursion_readdir ($ path, $ Deep);} else if (basename ($ path )! = '.' AND basename ($ path )! = '..') {// Not a folder. print the file name echo forChar ('-', $ Deep). basename ($ path ).'
';}} Closedir ($ resDir );}

The above PHP recursive traversal of the file implementation method in the specified folder is all the content shared by Xiaobian. I hope to give you a reference and support for PHP Chinese.

For more articles about PHP recursive file traversal in a specified folder, refer to PHP Chinese network!

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.