0

I need to figure out what subfolders are present on a bucket in order to decide what path to sync.

ls -r gs://<my_bucket>/**

returns all files and folders and I have a tree depth of >10 there!!

How can I get the list of folders and subfolders only and until a final depth of lets say 3 as with the find -maxdepth argument?

Thanks in advance

splaisan
  • 845
  • 6
  • 22
  • can you rephrase your question and explain what you really want to do..it will help in troubleshooting the issue – Divyani Yadav Dec 21 '21 at 11:30
  • I need to get the list of subfolders (not contained files) until a depth of three on the bucket to discover what names these folders have. I do not want to download (rsync) the whole bucker but only relevant subfolders after I can get their names from a ls like command. – splaisan Dec 22 '21 at 14:33

1 Answers1

2

As per documentation there is no such command mentioned to list the folders/subfolders using maximum depth in gsutil.

To get the top level objects of a bucket using node.js, it can be done by API as mentioned :

`const [files, nextQuery, apiResponse] = await storage.bucket(bucketName).getFiles({autoPaginate: false, delimiter: "/", prefix: ""});`

For more information you can refer to the link and github case where a similar issue has been discussed.

This command is mentioned as a trick : gsutil ls -l gs://bucket_name/folder_name | xargs -I{} gsutil du -sh {}

There's no --max-depth support in gsutil du. You could write a script that lists the first-level folder names, and then iterate over those folders and run gsutil ls -l $folder/*

Divyani Yadav
  • 1,030
  • 4
  • 9