Location: PHPKode > projects > PAS SiteManager > passitemanager/class/DirDelete.class.php
<?php
// Copyright 2002 Philippe Lewicki           hide@address.com
  /**
   * delete file Class
   *
   * It delete files recursivly
   *
   * @author Philippe Lewicki  <hide@address.com>
   * @version 2.0.3
   * @package PAS Package
   * @access public
   */

    class DirDelete extends BaseObject {
        var $dir_name ;
		
        function DirDelete($dir_name ="") {
			$this->dir_name = $dir_name;
			$this->setDisplayErrors(true) ; 
        }
        function delete($dir_file_name="") {
            $doDelete = true ;
            if ($dir_file_name == "") {
                $dir_file_name = $this->dir_name ;
            }
            if ($dir_file_name == "") {
                $this->setError("Missing File Parameters : dirname: ".$dir_file_name) ;
                $doDelete = false ;
            }
            if (!is_dir($dir_file_name) && !file_exists($dir_file_name)) {
                $this->setError($dir_file_name." doesn't seems to be a directory or a file.") ;
                $doDelete = false ;
            }
            if ($doDelete) {
				if (is_dir($dir_file_name)) {
					return rmdir($dir_file_name);
				} elseif (file_exists($dir_file_name)) {
					return unlink($dir_file_name) ;
				} else {
					return false;
				}
            } else {
                return false ;
            }
        }
        function recursiveDelete($dirName="") {
			if ($dirName == "") {
				$dirName = $this->dir_name;
			}
			if (strlen($dirName) > 0) {
				$d = dir($dirName);
				while($entry = $d->read()) {
					if ($entry != "." && $entry != "..") {
						if (is_dir($dirName."/".$entry)) {
							$this->recursiveDelete($dirName."/".$entry);
						} else {
							$this->delete($dirName."/".$entry) ;
						}
					}
				}
				if (!rmdir($dirName)) {
					$this->setError("Error File, couldn't delete ".$dirName);
				}
				$d->close();
				if ($this->isError()) {
					return false ;
				} else {
					return true ;
				}
			} else {
				return false;
			}
        }
    }


?>
Return current item: PAS SiteManager