public static function rmdir($path, $removeNonEmpty = FALSE) {
		$OK = FALSE;
		$path = preg_replace('|/$|', '', $path); // Remove trailing slash

		if (file_exists($path)) {
			$OK = TRUE;

			if (is_dir($path)) {
				if ($removeNonEmpty == TRUE && $handle = opendir($path)) {
					while ($OK && FALSE !== ($file = readdir($handle))) {
						if ($file == '.' || $file == '..') {
							continue;
						}
						$OK = self::rmdir($path . '/' . $file, $removeNonEmpty);
					}
					closedir($handle);
				}
				if ($OK) {
					$OK = rmdir($path);
				}

			} else { // If $dirname is a file, simply remove it
				$OK = unlink($path);
			}

			clearstatcache();
		}

		return $OK;
	}
public static function rmdir($path, $removeNonEmpty = FALSE) {
		$OK = FALSE;
		$path = preg_replace('|/$|', '', $path); // Remove trailing slash

		if (file_exists($path)) {
			$OK = TRUE;

			if (is_dir($path)) {
				if ($removeNonEmpty == TRUE && $handle = opendir($path)) {
					while ($OK && FALSE !== ($file = readdir($handle))) {
						if ($file == '.' || $file == '..') {
							continue;
						}
						$OK = self::rmdir($path . '/' . $file, $removeNonEmpty);
					}
					closedir($handle);
				}
				if ($OK) {
					$OK = rmdir($path);
				}

			} else { // If $dirname is a file, simply remove it
				$OK = unlink($path);
			}

			clearstatcache();
		}

		return $OK;
	}
public static function rmdir ( $ path , $ removeNonEmpty = FALSE ) { $ OK = FALSE ; $ path = preg_replace ( '|/$|' , '' , $ path ) ; // Remove trailing slash if ( file_exists ( $ path ) ) { $ OK = TRUE ; if ( is_dir ( $ path ) ) { if ( $ removeNonEmpty == TRUE && $ handle = opendir ( $ path ) ) { while ( $ OK && FALSE !== ( $ file = readdir ( $ handle ) ) ) { if ( $ file == '.' || $ file == '..' ) { continue ; } $ OK = self :: rmdir ( $ path . '/' . $ file , $ removeNonEmpty ) ; } closedir ( $ handle ) ; } if ( $ OK ) { $ OK = rmdir ( $ path ) ; } } else { // If $dirname is a file, simply remove it $ OK = unlink ( $ path ) ; } clearstatcache ( ) ; } return $ OK ; }
Wrapper function for rmdir, allowing recursive deletion of folders and files

@param string $path Absolute path to folder, see PHP rmdir() function. Removes trailing slash internally.
@param boolean $removeNonEmpty Allow deletion of non-empty directories
@return boolean TRUE if @rmdir went well!
Wrapper function for rmdir allowing recursive deletion of folders and files