note 61752 deleted from function.opendir by betz

From: Date: Sat, 11 Feb 2006 00:15:21 +0000
Subject: note 61752 deleted from function.opendir by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-103477@lists.php.net to get a copy of this message
Note Submitter: bobbfwed at comcast dot net ---- I have programmed a really nice program that remotely lets you manage files as if you have direct access to them (http://sourceforge.net/projects/filemanage/). I have a bunch of really handy functions to do just about anything to files or directories. In it I use a function to scan a directory and all subdirectories to get the number of files and directories and the total vollume. It goes through (recursivly) and adds the number of files/dirs/filesize to their respective global variables. Here is the function I made; it may need some tweaking to work for your uses. <?PHP // this function scans a directory and all subdirectories and returns some stats on them // it scans all files, instead of just accepted ones. // void scanfulldir( str 'directory path' ) *int 'number of directories counted' $number_of_dirs2 *int 'number of files counted' $number_of_files2 *int 'total size of files counted' $total_file_size2 function scanfulldir($dir){ if(!isset($GLOBALS['number_of_dirs2'])) $GLOBALS['number_of_dirs2'] = 0; if(!isset($GLOBALS['number_of_files2'])) $GLOBALS['number_of_files2'] = 0; if(!isset($GLOBALS['total_file_size2'])) $GLOBALS['total_file_size2'] = 0; if($handle = opendir($dir)){ // if the folder exploration is sucsessful, continue while(false !== ($file = readdir($handle))){ // as long as storing the next file to $file is successful, continue $path = $dir . '/' . $file; if(is_file($path)){ $GLOBALS['number_of_files2']++; $GLOBALS['total_file_size2'] += filesize($path); } else if(is_dir($path) && substr($file, 0, 1) != '.'){ $GLOBALS['number_of_dirs2']++; scanfulldir($path); } } closedir($handle); // close the folder exploration } } // end of scanfulldir() ?> This function is in 0.9.7 (the current release of File Manage). Hope this helps some people.

« previous php.notes (#103477) next »