I've been looking for a way to retrieve only directories inside a bucket but not what's in them.
As per Google Cloud Storage Docs one can filter by prefix by:
const Storage = require('@google-cloud/storage');
const storage = new Storage();
const options = {
prefix: prefix,
delimiter: '/'
};
storage
.bucket(bucketName)
.getFiles(options)
.then(results => {
const files = results[0];
console.log('Files:');
files.forEach(file => {
console.log(file.name);
});
})
.catch(err => {
console.error('ERROR:', err);
});
I've tried with several combinations using prefix: ""
, or prefix: "*"
or prefix: "\"
and so on but I can't get to make it return only the folders.
Has anybody been able to do it?