目录操作

阅读更多

 

1.查看目录大小

 

disk_free_space();

disk_total_space();

function directory_size($directory) {
      $directorySize=0;
      /* Open the directory and read its contents. */ 
      if ($dh = @opendir($directory)) {
         /* Iterate through each directory entry. */
         while (($filename = readdir ($dh))) {
            /* Filter out some of the unwanted directory entries. */
            if ($filename != "." && $filename != "..")
            {
               // File, so determine size and add to total.
               if (is_file($directory."/".$filename))
                  $directorySize += filesize($directory."/".$filename);
                  // New directory, so initiate recursion. */
                  if (is_dir($directory."/".$filename))
                     $directorySize += directory_size($directory."/".$filename);
            }
        } #endWHILE
     } #endIF
     @closedir($dh);
     return $directorySize;
   } #end directory_size()
 

2.删除目录

 

 

3.  创建多级目录

不能使用mkdir('aa/aa'); 建多级目录 .

private function _createDir($dir) {
    return is_dir($dir) or ($this->_createDir(dirname($dir)) and mkdir($dir, 0777));
}

你可能感兴趣的:(目录操作)