Remove a file if exists
@param string $filename The file name relative to the base_path()
@param boolean $public Optional True, indicates the file name is relative to public_path() else is relative to base_path()
@return boolean
321282
public static function removeFile($filename, $public = true) {
        if ($public) {
            $path = public_path($filename);
        } else {
            $path = base_path($filename);
        }
        if (file_exists($path)) {
            unlink($path);
        } else {
            return false;
        }
    }
429907
public static function remove(string $file = ''): bool
    {
        $file = static::normalizePath($file);
        if (static::exists($file)) {
            return @\unlink($file);
        }
        return false;
    }
164255
public function addFile($filename, $localname = null)
    {
        if (false === $this->openned) {
            return false;
        }
        if ((file_exists($this->filename) && !is_writable($this->filename))
            || !file_exists($filename)) {
            return false;
        }
        if (isset($localname)) {
            $localname = preg_replace("/(?:\.|\/)*(.*)/", "\\1", $localname);
            $localpath = dirname($localname);
            $tmpfilename = self::TMP_DIR . '/' . basename($localname);
        } else {
            $localname = basename($filename);
            $tmpfilename = self::TMP_DIR . '/' . $localname;
            $localpath = '';
        }
        if (file_exists($filename)) {
            copy($filename, $tmpfilename);
            $this->pclzip->delete(PCLZIP_OPT_BY_NAME, $localname);
            $this->pclzip->add($tmpfilename, PCLZIP_OPT_REMOVE_PATH, self::TMP_DIR, PCLZIP_OPT_ADD_PATH, $localpath);
            unlink($tmpfilename);
            return true;
        }
        return false;
    }
848744
public function delete($filename)
    {
        $this->initialize();

        try {
            $file = $this->matcher->getFile($filename);
        } catch (FileNotFoundException $e) {
            return;
        }

        foreach ($this->files as $key => $item) {
            if ($item->getFullPath() === $file->getFullPath()) {
                unset($this->files[$key]);
                $this->files = array_values($this->files); // normalize indexes
                $this->persist();
                break;
            }
        }
    }
945103
public function delete($bucketName, $fileName, $private = false)
    {
        $data = $this->get($bucketName, $fileName, $private, true);
        if ($data !== false && array_key_exists('x-bz-file-id', $data['headers'])) {
            $response = $this->client->b2DeleteFileVersion($this->apiURL, $this->token, $data['headers']['x-bz-file-id'], $fileName);

            return $response->isOk();
        }

        return false;
    }
526860
public function remove(string $filename, array $params = [])
    {
        $path = $this->buildDownloadsPath($filename);

        return $this->delete($path, $params);
    }
429375
public function deleteFile($containerName, $filePath, $relativePath)
    {
        return $this->getFactory()
            ->createStorage($containerName)
            ->deleteFile($containerName, $filePath, $relativePath);
    }
1217864
private function delete($filename, $isDir = false)
    {
        if ($this->isSFTP()) {
            $deleted = @$this->ftp->delete($filename, $isDir);
        } else {
            $deleted = @$this->ftpDelete($filename);
        }
        if (!$deleted) {
            $this->fail("couldn't delete {$filename}");
        }
        $this->debug("Deleted: {$filename}");
    }
255520
public function removeFile($key)
    {
        if (isset($this->files[$key])) {
            unset($this->files[$key]);
            return true;
        } else {
            return false;
        }
    }
555361
public static function delete($filename)
    {
        if (is_string($filename) && file_exists($filename)) {
            unlink($filename);
            return true;
        }

        return false;
    }
776002
public function exists($path, $public = true)
    {
        $path = $this->_relativepath($path, $public);

        return $this->_exists($path);
    }
965193
protected function _removeFile($file)
    {
        $_file = new File($file);

        if ($_file->exists()) {
            $_file->delete();

            $folder = $_file->folder();
            if (count($folder->find()) === 0) {
                $folder->delete();
            }
            return true;
        }
        return false;
    }
458000
public function deleteImageByName($filename)
    {
        $destinationPath = $this->getDestinationPath();

        $images = $this->getImages();

        foreach ($images as $key => $image) {
            if ($image->file == $filename) {
                foreach ($image->set as $imageSetFilename) {
                    $destination = $destinationPath . '/' . $imageSetFilename;
                    if (file_exists($destination)) {
                        unlink($destination);
                    }
                }
                unset($images[$key]);
            }
        }
        $images = array_values($images);
        $this->repository->images = $images;
        $this->save();
    }
1190933
public function remove() : bool
    {
        $private = self::PRIVATE_ABSOLUTE_PATH . $this->destination . $this->privateFileName;
        $public = self::PUBLIC_ABSOLUTE_PATH . $this->destination;

        if (file_exists($private) || file_exists($public))
        {
            FileSystem::delete($private);
            FileSystem::delete($public);

            return TRUE;
        }

        return FALSE;
    }
1174401
public static function removeExtension($filename)
    {
        if (false === strrpos($filename, '.')) {
            return $filename;
        }

        return substr($filename, 0, strrpos($filename, '.'));
    }
948960
public static function deleteThumbnail($filename) {
        $pos = strrpos($filename, '.');
        if ($pos === false) {
            return false;
        }
        $shortname = substr($filename, 0, $pos);
        $ext       = substr($filename, $pos);
        $filep     = $shortname . '-*' . $ext;
        $files     = glob($filep);
        if ($files) {
            foreach ($files as $f) {
                @unlink($f);
            }
        }

        return true;
    }
1149051
public function delete($path, $public = true)
    {
        $path = $this->_relativepath($path, $public);
        $this->_delete($path);
    }