Reputation: 53
I have some files and folders stored in gcs. I want to get all the files and folders given a specific directory.
I have managed to get all the files inside a directory by using delimiter and a prefix. But the response is excluding the subdirectories which i want to get also.
const prefix = `users/${currentUserName}/`;
const delimiter = "/";
const options = {
prefix: prefix
};
if (delimiter) {
options.delimiter = delimiter;
}
const [files] = await gcStorage.bucket(bucketName).getFiles(options);
I am getting outputs like:
I want outputs like:
Upvotes: 0
Views: 1258
Reputation: 81336
The sub-directories are returned as CommonPrefixes within the response (apiResponse.prefixes)
var query = {
delimiter: '/'
};
bucket.getFiles(query, function(err, files, nextQuery, apiResponse) {
// files is array of files
// apiResponse.prefixes is the same as CommonPrefixes
});
Refer to the documentation for an example: link
Upvotes: 1