src/FS/Folder/Editor.php
public static function removeFolder( $folderName, $force = FALSE, $strict = TRUE )
	{
		$folderName	= self::correctPath( $folderName);
		$count	= 1;																		//  current Folder is first Object
		if( !file_exists( $folderName ) )
		{
			if( $strict )
				throw new RuntimeException( 'Folder "'.$folderName.'" is not existing' );
			else
				return 0;
		}
		$index	= new DirectoryIterator( $folderName );
		foreach( $index as $entry )
		{
			if( !$entry->isDot() )
			{
				if( !$force )																	//  nested Files or Folders found
					throw new RuntimeException( 'Folder '.$folderName.' is not empty. See Option "force"' );
				if( $entry->isFile() || $entry->isLink() )
				{
					if( FALSE === @unlink( $entry->getPathname() ) )								//  remove File and count
						throw new RuntimeException( 'File "'.$folderName.$entry->getFilename().'" is not removable' );	//  throw Exception for File
					$count	++;
				}
				else if( $entry->isDir() )
				{
					$count	+= self::removeFolder( $entry->getPathname(), $force );					//  call Method with nested Folder
				}
			}
		}
		rmdir( $folderName );																//  remove Folder
		return $count;


		$dir	= dir( $folderName );														//  index Folder
		while( $entry = $dir->read() )														//  iterate Objects
		{
			if( preg_match( "@^(\.){1,2}$@", $entry ) )										//  if is Dot Object
				continue;																	//  continue
			$pathName	= $folderName.$entry;												//  Name of nested Object
			if( !$force )																	//  nested Files or Folders found
				throw new RuntimeException( 'Folder '.$folderName.' is not empty. See Option "force"' );
			if( is_file( $pathName ) )														//  is nested File
			{
				if( FALSE === unlink( $pathName ) )										//  remove File and count
					throw new RuntimeException( 'File "'.$pathName.'" is not removable' );	//  throw Exception for File
				$count	++;
			}
			if( is_dir( $pathName ) )														//  is nested Folder
				$count	+= self::removeFolder( $pathName, $force );							//  call Method with nested Folder
		}
		$dir->close();																		//  close Directory Handler
		rmDir( $folderName );																//  remove Folder
		return $count;																		//  return counted Objects
	}
public static function removeFolder( $folderName, $force = FALSE, $strict = TRUE )
	{
		$folderName	= self::correctPath( $folderName);
		$count	= 1;																		//  current Folder is first Object
		if( !file_exists( $folderName ) )
		{
			if( $strict )
				throw new RuntimeException( 'Folder "'.$folderName.'" is not existing' );
			else
				return 0;
		}
		$index	= new DirectoryIterator( $folderName );
		foreach( $index as $entry )
		{
			if( !$entry->isDot() )
			{
				if( !$force )																	//  nested Files or Folders found
					throw new RuntimeException( 'Folder '.$folderName.' is not empty. See Option "force"' );
				if( $entry->isFile() || $entry->isLink() )
				{
					if( FALSE === @unlink( $entry->getPathname() ) )								//  remove File and count
						throw new RuntimeException( 'File "'.$folderName.$entry->getFilename().'" is not removable' );	//  throw Exception for File
					$count	++;
				}
				else if( $entry->isDir() )
				{
					$count	+= self::removeFolder( $entry->getPathname(), $force );					//  call Method with nested Folder
				}
			}
		}
		rmdir( $folderName );																//  remove Folder
		return $count;


		$dir	= dir( $folderName );														//  index Folder
		while( $entry = $dir->read() )														//  iterate Objects
		{
			if( preg_match( "@^(\.){1,2}$@", $entry ) )										//  if is Dot Object
				continue;																	//  continue
			$pathName	= $folderName.$entry;												//  Name of nested Object
			if( !$force )																	//  nested Files or Folders found
				throw new RuntimeException( 'Folder '.$folderName.' is not empty. See Option "force"' );
			if( is_file( $pathName ) )														//  is nested File
			{
				if( FALSE === unlink( $pathName ) )										//  remove File and count
					throw new RuntimeException( 'File "'.$pathName.'" is not removable' );	//  throw Exception for File
				$count	++;
			}
			if( is_dir( $pathName ) )														//  is nested Folder
				$count	+= self::removeFolder( $pathName, $force );							//  call Method with nested Folder
		}
		$dir->close();																		//  close Directory Handler
		rmDir( $folderName );																//  remove Folder
		return $count;																		//  return counted Objects
	}
public static function removeFolder ( $ folderName , $ force = FALSE , $ strict = TRUE ) { $ folderName = self :: correctPath ( $ folderName ) ; $ count = 1 ; //  current Folder is first Object if ( ! file_exists ( $ folderName ) ) { if ( $ strict ) throw new RuntimeException ( 'Folder "' . $ folderName . '" is not existing' ) ; else return 0 ; } $ index = new DirectoryIterator ( $ folderName ) ; foreach ( $ index as $ entry ) { if ( ! $ entry -> isDot ( ) ) { if ( ! $ force ) //  nested Files or Folders found throw new RuntimeException ( 'Folder ' . $ folderName . ' is not empty. See Option "force"' ) ; if ( $ entry -> isFile ( ) || $ entry -> isLink ( ) ) { if ( FALSE === @ unlink ( $ entry -> getPathname ( ) ) ) //  remove File and count throw new RuntimeException ( 'File "' . $ folderName . $ entry -> getFilename ( ) . '" is not removable' ) ; //  throw Exception for File $ count ++ ; } else if ( $ entry -> isDir ( ) ) { $ count += self :: removeFolder ( $ entry -> getPathname ( ) , $ force ) ; //  call Method with nested Folder } } } rmdir ( $ folderName ) ; //  remove Folder return $ count ; $ dir = dir ( $ folderName ) ; //  index Folder while ( $ entry = $ dir -> read ( ) ) //  iterate Objects { if ( preg_match ( "@^(\.){1,2}$@" , $ entry ) ) //  if is Dot Object continue ; //  continue $ pathName = $ folderName . $ entry ; //  Name of nested Object if ( ! $ force ) //  nested Files or Folders found throw new RuntimeException ( 'Folder ' . $ folderName . ' is not empty. See Option "force"' ) ; if ( is_file ( $ pathName ) ) //  is nested File { if ( FALSE === unlink ( $ pathName ) ) //  remove File and count throw new RuntimeException ( 'File "' . $ pathName . '" is not removable' ) ; //  throw Exception for File $ count ++ ; } if ( is_dir ( $ pathName ) ) //  is nested Folder $ count += self :: removeFolder ( $ pathName , $ force ) ; //  call Method with nested Folder } $ dir -> close ( ) ; //  close Directory Handler rmDir ( $ folderName ) ; //  remove Folder return $ count ; //  return counted Objects }
Removes a Folder recursive and returns Number of removed Folders and Files.
Because there where Permission Issues with DirectoryIterator it uses the old 'dir' command.
@access		public
@static
@param		string		$folderName		Folder to be removed
@param		bool		$force			Flag: force to remove nested Files and Folders
@return		int
Removes a Folder recursive and returns Number of removed Folders and Files . Because there where Permission Issues with DirectoryIterator it uses the old dir command .