Location: PHPKode > projects > ZZ/OSS Installer > zic-1.1.0dev1/installer/lib/ZZOSS_Dir/Dir.php
<?php 
    /*
    Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    /**
    @version $Id: Dir.php,v 1.3 2004/04/06 14:45:37 ordnas Exp $
    @copyright Copyright &copy; 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
    @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
    */
    
    //require_once 'PEAR.php';
    
/**
* Helper methods for several occasions.
*/
class ZZOSS_Dir
{
    /**
    * removes directory recursively, even if non-empty 
	*/ 
    function rm($dir) { 
		return System::rm(array('-rf', $dir));
	} 
 
 
	/* 
	* MY MKDIR 
	* 
	* make directories recursively 
	*/ 
	function mk($dir)
	{
		System::mkDir(array('-p', $dir));
	} 
    
	function copy($src, $dest, $ignore_list = array(), $recursive = true, $overwrite = true)
	{
        $src = ZZOSS_File::fixPath($src.DIRECTORY_SEPARATOR);
        $dest = ZZOSS_File::fixPath($dest.DIRECTORY_SEPARATOR);
        
		// lowercase all entries in ignorelist
		foreach($ignore_list as $key => $val) {
			$ignore_list[$key] = strtolower($val);
		}
	  	if(is_dir($src)){
			if (!ZZOSS_Dir::_copyRec($src, $dest, $ignore_list, $recursive, $overwrite)){
				return false;
            }
			if (is_file($src) && ($overwrite || !file_exists($dest))){ // do regular copy
				if (!copy($src, $dest)){
					return false;
                }
            }
        }
		return true;
	}


    function _copyRec($src, $dest, $ignore_list = array(), $recursive = true, $overwrite = true)
    {
        //$CMD = 'mv '.$src.' '.$dest;
        //exec($CMD);
        //echo $src.' -> '.$dest.'<br/>';
        System::mkdir(array('-p',$dest));
        
        $handle = opendir($src);
        while ($file = readdir($handle)){
            if(!in_array(strtolower($file), $ignore_list)) {
                $src_file = $src.$file;
                //echo ' -> ';
                $dest_file = $dest.$file;
                //echo '<br/>';
                if ($recursive && is_dir($src_file) && $file !="." && $file != "..")
                    if (!ZZOSS_Dir::_copyRec($src_file.DIRECTORY_SEPARATOR, $dest_file.DIRECTORY_SEPARATOR, $ignore_list, $recursive, $overwrite))
                        return false;
                if (is_file($src_file) && ($overwrite || !file_exists($dest_file)))
                    if (!copy($src_file, $dest_file))
                        return false;
            }
        }
        closedir($handle);
        return true;
	}
    
    function mtime($dir, $recursive = true) {
        
        $dir .= DIRECTORY_SEPARATOR;
        
        $d = dir($dir);
        
        $currentModified    = 0;
        $lastModified       = filemtime($dir.'.');
        
        while($entry = $d->read()) {
            if ($entry != "." && $entry != "..") {
                if ($recursive && is_dir($dir.DIRECTORY_SEPARATOR.$entry)) {
                    $currentModified = ZZOSS_Dir::mtime($dir.DIRECTORY_SEPARATOR.$entry, true);
                }
                if ($currentModified > $lastModified){
                    $lastModified = $currentModified;
                }
            }
        }
        $d->close();
        
        return $lastModified;
    }
}
?>
Return current item: ZZ/OSS Installer