Google-cloud-php: [ASK] - Show Only Folders on Objects List

Created on 31 Aug 2020  路  2Comments  路  Source: googleapis/google-cloud-php

Hello, guys

Before the questions, this is the general Info:
The total of my objects is more than 12000 items. There are a few folders, for example:
1 Afolder / Afolder2
2 file.mp4
3 Bfolder
============================ next page ============================
115 Cfolder / Cfolder2 / Cfolder3
116 file.mp4
117 file.mp4
============================ page lately ============================
12478 YFolder / many items in this folder
12479 file.mp4
12480 lastfile.mp4

My questions are:

  1. How to show only folders when we're using ->objects()->info() without files inside and without getting all objects? Because if I limit, let's say until 100 results, YFolder is not in the result because YFolder is in the last of the result (according to the above information YFolder is in the order of 12478)

In the current situation the result of ->object->info() is: (I just put a "name key" for sample)
"name":"folder"
"name":"folder/folder2"
"name":"folder/folder2/file.mp4"

  1. Is it possible for me if I just wanna show "folder and folder2"?

Hope my question could be understood, thank you in advance.

Regards,
Marcopolooo

storage question

All 2 comments

@marcopolooo, not quite sure what you need.

You can list all objects and "folders" using prefix and delimiter options. But you'll have to iterate all objects in "folder" to get all "subfolders". If you don't need objects you can just ignore them and get "folder" names with prefixes() method. Like this:

$objects = $bucket->objects([
    'prefix' => 'folder/',
    'delimiter' => '/',
]);
foreach ($objects as $o) {}
$folderNames = $objects->prefixes();

Hi folks,

@ava12's response is the recommended guidance if you want to simulate a file system by using a delimiter and prefix. If you want first level of folders you would do: delimiter: '/' and prefix: ''.

@dwsupplee I think we can close this issue out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  8Comments

castaneai picture castaneai  路  4Comments

tmatsuo picture tmatsuo  路  4Comments

ammopt picture ammopt  路  6Comments

joseflorido picture joseflorido  路  3Comments