PHP Methods for directory operations

Source: Internet
Author: User
This article mainly introduces the method of PHP for directory operation, the interested friend's reference, hope to be helpful to everyone.

This article describes how PHP calculates the entire directory size, in the following ways:

/** * Calculate The full size of a directory * * @author   Jonas John * @version   0.2 * @param    string  $Direct Orypath  Directory path */function calcdirectorysize ($DirectoryPath) {  //I reccomend using a Normalize_path function here  /Sure $DirectoryPath contains an ending slash  //To display a good looking size can us e a readable_filesize  //function.  $Size = 0;  $Dir = Opendir ($DirectoryPath);  if (! $Dir)    return-1;  while ($File = Readdir ($Dir))!== false) {    //Skip File pointers    if ($File [0] = = '. ') continue;     Go recursive down, or add the file size    if (Is_dir ($DirectoryPath. $File))            $Size + = Calcdirectorysize ($Direc Torypath. $File. Directory_separator);    else       $Size + = FileSize ($DirectoryPath. $File);      }  Closedir ($Dir);  return $Size;} Example of use: $SizeInBytes = calcdirectorysize (' data/');

Summary: the above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

Implementation techniques of PHP unordered tree

PHP Process Control and mathematical operations

PHP sends post, get requests, and action cookies based on Curl

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.