Remove a file/directory

@param string|Object $path      the path to remove
@param bool          $recursive recurse
@param bool          $force     force

@throws \RuntimeException
@throws \InvalidArgumentException
@return string
970583
public function remove($path, $recursive, $force)
    {
        $this->clearAll();

        $path = trim($path);
        if (!$this->validatePath($path)) {
            throw new \InvalidArgumentException('Invalid path');
        }

        $this->addCommandName(self::GIT_REMOVE);

        if ($recursive) {
            $this->addCommandArgument('-r');
        }

        if ($force) {
            $this->addCommandArgument('-f');
        }

        $this->addPath($path);

        return $this->getCommand();
    }
206719
private function recursiveDeletePath($path, $mask)
    {
        if (!file_exists($path) || !is_dir($path) || !is_readable($path)) {
            $this->logger->warning("Directory '{$path}' is not readable. Skip...");

            return;
        }

        $objects = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($path),
            \RecursiveIteratorIterator::SELF_FIRST
        );

        foreach ($objects as $name => $object) {
            if (preg_match($mask, $name)) {
                @unlink($name);
            }
        }
    }
1089039
public function delete($recursive = false)
    {
        $fs = FileSystem::getFileSystem();
        if ($fs->canDelete($this) !== true) {
            throw new IOException("Cannot delete " . $this->path . "\n");
        }

        $fs->delete($this, $recursive);
    }
386309
protected function findCommandsIn($path, $recursive = false)
    {
        $classes = [];
        foreach ($this->findCommandsFiles($path) as $filePath) {

            //$class = $classFinder->findClass($filePath);

            $class = Util::getClassNameFromFile($filePath);
            if ($class !== null) {
                $namespace = Util::getNamespaceFromFile($filePath);
                if ($namespace !== null) {
                    $class = "$namespace\\$class";
                }
                $class = Str::removeLeft($class, '\\');
                $parents = class_parents($class);

                if ($this->findCommandsExtending !== null && in_array($this->findCommandsExtending, $parents, true) === false) {
                    continue;
                }
                $ref = new \ReflectionClass($class);
                if ($ref->isAbstract()) {
                    continue;
                }
                $classes[] = Str::removeLeft($class, '\\');
            }
        }

        return $classes;
    }
302909
public function delete(PhingFile $f, $recursive = false)
    {
        if ($f->isDirectory()) {
            $this->rmdir($f->getPath(), $recursive);
        } else {
            $this->unlink($f->getPath());
        }
    }
211830
public static function remove($path, $parent = true)
    {
        $ok = true;
        if (true===self::ensureExists($path)) {
            if (false===@is_dir($path) || true===is_link($path)) {
                return @unlink($path);
            }
            $iterator = new \RecursiveIteratorIterator(
                new \RecursiveDirectoryIterator($path),
                \RecursiveIteratorIterator::SELF_FIRST | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS
            );
            foreach($iterator as $item) {
                if (in_array($item->getFilename(), array('.', '..'))) {
                    continue;
                }
                if ($item->isDir()) {
                    $ok = self::remove($item);
                } else {
                    $ok = @unlink($item);
                }
            }
            if ($ok && $parent) {
                @rmdir($path);
            }
            @clearstatcache();
        }
        return $ok;
    }
1313416
public static function files($path, $recursive = false, $toArray = false, $pathType = self::PATH_ABSOLUTE)
	{
		/**
		 * Files callback
		 *
		 * @param \SplFileInfo                $current  Current item's value
		 * @param string                      $key      Current item's key
		 * @param \RecursiveDirectoryIterator $iterator Iterator being filtered
		 *
		 * @return boolean   TRUE to accept the current item, FALSE otherwise
		 */
		$callback = function ($current, $key, $iterator) {
			return $current->isFile();
		};

		$files = static::findByCallback($path, $callback, $recursive);
		
		if ($toArray) {
		    $files = static::toArray($files, $pathType);
		}
		
		return $files;
	}
191818
public function listFiles(string $path = '', bool $recursive = false)
    {
        $contents = $this->listContents($path, $recursive);

        $filter = function ($object) {
            return $object['type'] === 'file';
        };

        return \array_values(\array_filter($contents, $filter));
    }
814106
public static function rmWorkingCopy($path, $recursive = true)
    {
        $returnValue = (bool) false;

        
		
		if (is_file($path)) {
			if(preg_match('/^\//', $path)){
				$returnValue = @unlink($path);
			}
		} else if ($recursive) {
			if (is_dir($path)) {
				$iterator = new DirectoryIterator($path);
				foreach ($iterator as $fileinfo) {
					if (!$fileinfo->isDot()) {
						self::rmWorkingCopy($fileinfo->getPathname(), true);
					}
					unset($fileinfo);
				}
				unset($iterator);
				$returnValue = @rmdir($path);
			}
		}
						
        

        return (bool) $returnValue;
    }
829659
private function createDir($path, $chmod = 0777, $recursive = true)
    {
        if (!mkdir($path, $chmod, $recursive)) {
            throw new RuntimeException(
                sprintf(
                    'The directory path "%s" could not be created.',
                    $path
                )
            );
        }
    }
1227646
protected function remove($path, $force = false) {
		$stat = $this->stat($path);
		$stat['realpath'] = $path;
		if (!empty($stat['tmb']) && $stat['tmb'] != "1") {
			$this->rmTmb($stat['tmb']);
		}
		$this->clearcache();
		
		if (empty($stat)) {
			return $this->setError(elFinder::ERROR_RM, $this->_path($path), elFinder::ERROR_FILE_NOT_FOUND);
		}
		
		if (!$force && !empty($stat['locked'])) {
			return $this->setError(elFinder::ERROR_LOCKED, $this->_path($path));
		}
		
		if ($stat['mime'] == 'directory') {
			foreach ($this->_scandir($path) as $p) {
				$name = $this->_basename($p);
				if ($name != '.' && $name != '..' && !$this->remove($p)) {
					return false;
				}
			}
			if (!$this->_rmdir($path)) {
				return $this->setError(elFinder::ERROR_RM, $this->_path($path));
			}
			
		} else {
			if (!$this->_unlink($path)) {
				return $this->setError(elFinder::ERROR_RM, $this->_path($path));
			}
		}

		$this->removed[] = $stat;
		return true;
	}
762113
public void deletePath(final Path path, final boolean recursive) {
    this.futures.add(new NamedFuture(this.executor.submit(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Lock lock = ParallelRunner.this.locks.get(path.toString());
        lock.lock();
        try {
          HadoopUtils.deletePath(ParallelRunner.this.fs, path, recursive);
          return null;
        } finally {
          lock.unlock();
        }
      }
    }), "Delete path " + path));
  }
493295
public static function recursiveDelete($path) {
		if(is_file($path)) {
			@unlink($path);

		} else {
			$it = new RecursiveIteratorIterator(
				new RecursiveDirectoryIterator($path),
				RecursiveIteratorIterator::CHILD_FIRST
			);

			foreach ($it as $file) {
				if (in_array($file->getBasename(), array('.', '..'))) {
					continue;
				}elseif ($file->isDir()) {
					rmdir($file->getPathname());
				}elseif ($file->isFile() || $file->isLink()) {
					unlink($file->getPathname());
				}
			}
			rmdir($path);
		}

		return false;
	}
360792
public static function chownPath($path, $user = null, $recursive = true)
    {
        $path = realpath($path);
        if (empty($path)) {
            return false;
        }

        if (empty($user)) {
            $user = self::getDefaultUser();
        }
        self::chown($path, $user, $recursive);
        return true;
    }
1035765
private function rmdir($dir, $recursive)
	{
		$is_link = is_link($dir);
		if($is_link)
		{
			if(! unlink($dir))
				throw new Exception("Error unlinking $dir");
		}
		else if(! $recursive)
		{
			if(! rmdir($dir))
				throw new Exception("Error removing temp dir: $dir");
		}
		else
		{
			$dh = opendir($dir);
			if(! $dh)
				throw new Exception("Cannot read temp dir contents for removal: $dir");

			do
			{
				$file = readdir($dh);
				if($file === false)
					break;

				// Don't delete current dir or parent dir (yet)
				if($file === '.' || $file === '..')
					continue;

				$path = $dir .DIRECTORY_SEPARATOR. $file;

				$is_link = is_link($path);
				$is_dir = is_dir($path);

				if($is_dir && ! $is_link)
				{
					$this->rmdir($path, true);
				}
				else // anything else, should be able to unlink
				{
					if(! unlink($path))
						throw new Exception("Cannot remove nested temp file: $path");
				}
			}
			while($file !== false);

			closedir($dh);

			// Now remove the dir itself (non-recursive, it should now be empty)
			$this->rmdir($dir, false);
		}
	}
365903
protected function removeTemporaryFiles($filepath, $force = false)
	{
		if ($force || $filepath !== $this->getUncompressedFilepath($filepath)) {
			$this->getBackupFilesystemInstance()->removeFile($this->getUncompressedFilepath($filepath));
		}
	}
1009688
protected function doRawList($dir, $recursive = false)
    {
        $connection = $this->connection;

        return $this->retry(function () use ($connection, $dir, $recursive) {
            $res = @ftp_rawlist($connection, $dir, $recursive);

            if (false === $res) {
                throw new \RuntimeException("Rawlist failed: ".$dir);
            }

            $items = array();

            foreach ($res as $child) {
                $chunks = preg_split("/\s+/", $child);
                list($item['rights'], $item['number'], $item['user'], $item['group'], $item['size'], $item['month'], $item['day'], $item['time']) = $chunks;
                $item['type'] = $chunks[0]{0}
                === 'd' ? 'directory' : 'file';
                array_splice($chunks, 0, 8);
                $item['name'] = implode(" ", $chunks);
                $item['pathname'] = \rtrim($dir, '/').'/'.$item['name'];
                $items[] = $item;
            }

            return $items;
        });
    }