note 61752 added to function.opendir

From: Date: Fri, 10 Feb 2006 23:53:26 +0000
Subject: note 61752 added to function.opendir
Groups: php.notes 
Request: Send a blank email to php-notes+get-103474@lists.php.net to get a copy of this message
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. ---- Server IP: 64.71.164.2 Probable Submitter: 67.181.154.141 ---- Manual Page -- http://www.php.net/manual/en/function.opendir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61752 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61752&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61752&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61752&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61752&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61752&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61752&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61752&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61752&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103474) next »