Check whether a folder is empty or not in order to delete this folder.

@param integer $folderId The folder id to check whether it has files or not.
@return boolean
970199
public function actionIsFolderEmpty($folderId)
    {
        $count = StorageFile::find()->where(['folder_id' => $folderId, 'is_deleted' => false])->count();
        
        return [
            'count' => $count,
            'empty' => $count > 0  ? false : true,
        ];
    }
319689
public function get_folder_name($folderid) {
        if (empty($folderid)) {
            throw new coding_exception('Empty folderid passed to get_folder_name');
        }

        // Cache based on oauthtoken and folderid.
        $cachekey = $this->folder_cache_key($folderid);

        if ($foldername = $this->foldernamecache->get($cachekey)) {
            return $foldername;
        }

        $url = self::API."/{$folderid}";
        $ret = json_decode($this->get($url));
        if (isset($ret->error)) {
            $this->log_out();
            return false;
        }

        $this->foldernamecache->set($cachekey, $ret->name);
        return $ret->name;
    }
109310
public function empty($something, $nullValid = false): bool
    {
        return (('' === $something || (NULL === $something && !$nullValid)) && 0 !== $something && '0' !== $something);
    }
862349
protected function isGranted($fileID)
    {
        // Since permissions are applied to the non-variant only,
        // map back to the original file before checking
        $parsedFileID = $this->getProtectedResolutionStrategy()->stripVariant($fileID);

        // Make sure our File ID got understood
        if ($parsedFileID && $originalID = $parsedFileID->getFileID()) {
            $session = Controller::curr()->getRequest()->getSession();
            $granted = $session->get(self::GRANTS_SESSION) ?: array();
            return !empty($granted[$originalID]);
        }

        // Our file ID didn't make sense
        return false;
    }
193061
public function getRoot($folderId)
    {
        $folder = FolderQuery::create()->findPk($folderId);

        if (0 !== $folder->getParent()) {
            $parentFolder = FolderQuery::create()->findPk($folder->getParent());

            if (null !== $parentFolder) {
                $folderId = $this->getRoot($parentFolder->getId());
            }
        }

        return $folderId;
    }
354083
public function has($iElementID)
    {
        if (empty($iElementID) || $this->isEmpty()) {
            return false;
        }

        return in_array($iElementID, (array) $this->arElementIDList);
    }
256149
public function deleteFolderAsyncWithHttpInfo($folderId)
    {
        $returnType = '';
        $request = $this->deleteFolderRequest($folderId);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
270876
public function clearCacheFile($elementId)
    {
        // get all possible caches
        $elements = HtmlCacheElement::findAll(['elementId' => $elementId]);
        // \craft::Dd($elements);
        $cacheIds = array_map(function ($el) {
            return $el->cacheId;
        }, $elements);

        // get all possible caches
        $caches = HtmlCacheCache::findAll(['id' => $cacheIds]);
        foreach ($caches as $cache) {
            $file = $this->getCacheFileName($cache->uid);
            if (file_exists($file)) {
                @unlink($file);
            }
        }


        // delete caches for related entry
        HtmlCacheCache::deleteAll(['id' => $cacheIds]);
        return true;
    }
997637
public function delete($fileIDs)
    {
        if (is_array($fileIDs)) {
            $fileIDs = implode(',', $fileIDs);
        }

        $data = [
            'file_ids' => $fileIDs
        ];

        return $this->post('files/delete', $data, \true);
    }
419081
public function mkdir($directory = null)
    {
        if (\ftp_mkdir($this->_stream, $directory)) {
            return true;
        }

        $this->error = 'Failed to create directory "'.$directory.'"';

        return false;
    }
970858
public function get_folder_items($folderid = 0) {
        $this->reset_state();
        $result = $this->request($this->make_url("/folders/$folderid/items",
            array('fields' => 'id,name,type,modified_at,size,owned_by')));
        return json_decode($result);
    }
1339034
public function delete($file_id)
    {
        if (empty($file_id)) {
            return false;
        }

        $deleted = $count = 0;
        foreach ((array) $this->file->getList(array('file_id' => $file_id)) as $file) {
            $deleted += (int) $this->file->delete($file['file_id']);
            $count++;
        }

        return $count && $count == $deleted;
    }
1230123
public function cleanDir($directory)
    {
        if (!$files = $this->nlist($directory)) {
            return $this->isEmpty($directory);
        }

        // remove children
        foreach ($files as $file) {
            $this->remove($file, true);
        }

        return $this->isEmpty($directory);
    }
75913
public function hasItem($cacheId)
    {
        $cacheId = $this->normalizeKey($cacheId);

        return $this->cache->has($cacheId);
    }
8267
public static function remove_folder_if_empty($folder, $recursive = true)
    {
        if (!is_readable($folder)) {
            return false;
        }
        $handle = opendir($folder);
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {
                // if an empty folder is detected, remove that one first and move on
                if ($recursive && is_dir($entry) && self::remove_folder_if_empty($entry)) {
                    continue;
                }
                // if a file was encountered, or a subdirectory was not empty, return false.
                return false;
            }
        }
        // if we are still here, the folder is empty.
        rmdir($folder);
        return true;
    }
751314
private function ftpDelete($directory)
    {
        // here we attempt to delete the file/directory
        if (!(@ftp_rmdir($this->ftp, $directory) || @ftp_delete($this->ftp, $directory))) {
            // if the attempt to delete fails, get the file listing
            $filelist = @ftp_nlist($this->ftp, $directory);

            // loop through the file list and recursively delete the FILE in the list
            foreach ($filelist as $file) {
                $this->ftpDelete($file);
            }

            // if the file list is empty, delete the DIRECTORY we passed
            $this->ftpDelete($directory);
        }
        return true;
    }
1095735
public function delete($photoId)
    {
        $photo = $this->dataStore->getPhoto($photoId);

        if (!$photo) {
            // Photo does not exists, lets assume its deleted
            return true;
        }

        $storage = $this->storageManager->get($photo['storage_name']);

        if ($this->dataStore->deletePhoto($photoId) && $storage->deletePhoto($photo['file_path'])) {
            return true;
        }

        return false;
    }