note 37393 added to function.filesize

From: Date: Thu, 13 Nov 2003 14:55:53 +0000
Subject: note 37393 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-60334@lists.php.net to get a copy of this message
// Functions in this file: // myMove: moves a directory to specified location // recurseMove: Only copies contents of one directory // to another, wrongly named. // recurseDel: To delete a directory // recurseSize: To get size of a directory // in bytes // Start Function function myMove($newLoc,$oldLoc){ recurseMove($newLoc,$oldLoc); recurseDel($oldLoc); rmdir($oldLoc); }// End Function // function "recurseMove" begins function recurseMove($newLoc,$oldLoc){ // newLoc is destination directory, relative or absolute path // oldLoc is directory to be copied, relative or absolute path. // copy takes place as newLoc/"contents of oldLoc" $dirOpened=opendir($oldLoc); // Open the source directory // first. // If destination dir doesnt exist, create it. if(!file_exists($newLoc)) mkdir($newLoc); // List the directory. while (false != ($filename = readdir($dirOpened))) { // Do not copy special directories "." and ".." if($filename !="." && $filename !=".." ){ // Get reference to source file $myFile = $oldLoc.'/'.$filename; // If its a directory, then first copy it by // recursion. if (is_dir($myFile)) recurseMove($newLoc.'/'.$filename,$myFile); else // Perform copy immediately if its a file. copy($myFile,$newLoc.'/'.$filename); } } // function "recurseMove" ends function recurseDel($oldLoc){ // function "recurseDel" begins // oldLoc is directory to be removed, relative or absolute path. $dirOpened=opendir($oldLoc); // Open the directory first. $flag = 0; // variable to determine if Directory is empty. while (false !== ($filename = readdir($dirOpened))) if($filename !="." && $filename !=".." ){ // obtain an array of all file/directory names $files[] = $filename; $flag =1; } // Close the handle to the directory closedir($dirOpened);// very important: cannot delete // directories if we have handles that // point to them or their sub-directories // open. // Flag will be zero if "." & ".." were the only directories found if($flag == "1") for($i=0;$i<count($files);$i++){ // prepare the path and filename to be deleted $myFile = $oldLoc.'/'.$files[$i]; // If its a dir, delete its contents first thru recursion if(is_dir($myFile)){ recurseDel($myFile); rmdir($myFile); // will work only if handle to all // sub-directories closed } else // Perform delete immediately if its a file. unlink($myFile); } }// function "recurseDel" ends //function "recurseSize" begins function recurseSize($Loc,$app_auth){ $dirOpened=opendir($Loc); // Open the directory first. $flag = 0; // variable to determine if Directory is empty. $size = 0; while (false !== ($filename = readdir($dirOpened))) if($filename !="." && $filename !=".." ){ $files[] = $filename; $flag =1; } if($flag == "1") for($i=0;$i<count($files);$i++){ $myFile = $Loc.'/'.$files[$i]; if (is_dir($myFile)) $size += recurseSize($myFile,$app_auth); else if(is_file($myFile)) //Echo "File"; $size += filesize($myFile); } // will return "0" if directory was empty return $size; }// function "recurseSize" end ?> ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37393 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37393&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37393&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60334) next »