Example #1
0
	/**
	 * _readAll()  - давайте мыслить рекурсивно!
	 * 
	 * @param $path
	 * @return (int)
	 */
	function _readAll($path=""){
		global $size;
		if(is_dir($path)){
			$initial = _readDir($path);
		}
		
		//are there subdirs?
		if(count($initial)>0){
			while(list($key,$val)=each($initial)){
				if(strlen($path)>0){
					$mypath = $path . "/" . $val;
				}else{
					$mypath = $val;
				}
				$overall = $overall + _readAll($mypath);				
				//echo $mypath . "<br>";			
			}
		}
		
		//read files
		if(is_dir($path)){
			$files = _readPHP($path);
		}else{
			$files = array();
		}
		
		while(list($key,$val)=each($files)){
			//open each file and check how many lines of code it has
			if(strlen($path)>0){
				$mypath = $path . "/" . $val;
			}else{
				$mypath = $val;
			}
			$file = fopen($mypath, "r");
			$rf = fread($file, 100000);
			$temp = explode("\n",$rf);
			$tot = count($temp);
			//echo "--" . $val . " : lines " . $tot . "<br>";
			$overall = $overall + $tot;
			$size = $size + filesize($mypath);
			fclose($file);
		}		
		//echo "<b> TOT: </b>" . $overall;		
		return $overall;
	}
function _readDir($dirPath, &$filePaths)
{
    // The rest of the file contains one record for each directory entry.  Each
    // record contains a number of ordered fields as described below.  The fields
    // are terminated by a line feed (0x0a) character.  Empty fields are
    // represented by just the terminator.  Empty fields that are only followed by
    // empty fields may be omitted from the record.  Records are terminated by a
    // form feed (0x0c) and a cosmetic line feed (0x0a).
    //
    // By matching records which follow a form feed and a line feed (\f\n) we
    // ignore the first record, which is for this directory.
    //
    // (?:[^\f\n]*\n){20} matches the 20 don't care fields between the name field
    // and the deleted field.  It is enclosed in (?:)? because empty fields that
    // are only followed by empty fields may be omitted from the record.
    //
    // @see libsvn_wc/README
    //
    // $match[1] is the name field
    // $match[2] is the kind field
    // $match[3] is the deleted field, if present
    preg_match_all('/\\f\\n([^\\f\\n]*)\\n([^\\f\\n]*)\\n(?:(?:[^\\f\\n]*){20}([^\\f\\n]*)\\n)?/', file_get_contents("{$dirPath}/.svn/entries"), $matches, PREG_SET_ORDER);
    foreach ($matches as $match) {
        switch ($match[2]) {
            case 'dir':
                _readDir($dirPath . '/' . $match[1], $filePaths);
                break;
            case 'file':
                $filePaths[] = $dirPath . '/' . $match[1];
                break;
            default:
                /** @todo */
                echo "ERROR\n";
        }
    }
}