note 64019 added to ref.filesystem

From: Date: Wed, 05 Apr 2006 16:58:22 +0000
Subject: note 64019 added to ref.filesystem
Groups: php.notes 
Request: Send a blank email to php-notes+get-107392@lists.php.net to get a copy of this message
The following underlisted function called "fcountext" is a function I wrote, for counting the number of file extensions within a given directory. Hope you find it satisfactory as there is no alternative solution via PHP's core filesystem's functions for counting the number of file extensions within a given directory. <?php /* * Author: ORUNTA C. N. * Email: codatrix@yahoo.com * * Name: fcountext() * Function: To count the number of file extensions within a given directory. * Argument(s): $dir, i.e. directory path - for e.g. 'htdocs/yahoo/' * Return-type: Integer */ function fcountext($dir) { //Authenticate - if directory? if(is_dir($dir)) { //Open and establish directory handle/pointer $dp = opendir($dir); //Create extensible array $afile = array(); //Set initializer array; $i = 0; //Read contents of directory into array $afile, thus: while($content = readdir($dp)) { //Concatenate filepath $filepath = $dir.$content; //Confirm any initial value within array... if(!count($afile)) { //Authenticate - if file? if(is_file($filepath)) { //Get extension using PHP's 'pathinfo' $pathinfo = pathinfo($filepath); //Store into the array $afile[$i] = $pathinfo['extension']; } } else { //Authenticate - if file? if(is_file($filepath)) { //Get extension using PHP's 'pathinfo' $pathinfo = pathinfo($filepath); //Count array into $len $len = count($afile); //Compare $pathinfo['extension'] with elements of array $afile for($i=0; $i<$len; $i++) { if($afile[$i] != $pathinfo['extension']) $stat = 'T'; else { $stat = 'F'; break; } } //If Status is true, then store into array if($stat == 'T') { $afile[$len] = $pathinfo['extension']; } } } } //Count total no. of different extensions. $extnum = count($afile); //Return no. of ext. return $extnum; //Close directory closedir($dp); } else { //Return no Value return 'Invalid Directory'; } } ?> The above function can be incorporated as you deem fit into a class situation to be accessed publicly. ---- Server IP: 192.117.122.43 Probable Submitter: 81.199.198.3 (proxied: 81.199.198.3) ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.filesystem.php Edit -- http://master.php.net/note/edit/64019 Del: integrated -- http://master.php.net/note/delete/64019/integrated Del: useless -- http://master.php.net/note/delete/64019/useless Del: bad code -- http://master.php.net/note/delete/64019/bad+code Del: spam -- http://master.php.net/note/delete/64019/spam Del: non-english -- http://master.php.net/note/delete/64019/non-english Del: in docs -- http://master.php.net/note/delete/64019/in+docs Del: other reasons-- http://master.php.net/note/delete/64019 Reject -- http://master.php.net/note/reject/64019 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107392) next »