List all files in a GCS Bucket from Vertex Notebook
2 min readMay 24, 2024
Hey guys, in today’s very short blog we will see how we can List all files in a GCS Bucket from Vertex Notebook. So without any further due, let’s do it…
Read the full article here — https://machinelearningprojects.net/list-all-files-in-a-gcs-bucket-from-vertex-notebook/
Steps to List all files in a GCS Bucket from Vertex Notebook
- Please open a new Python notebook and paste the following code into it.
- Now change the variables like ‘bucket_name’, and ‘prefix’.
- And finally, run the code.
Code
# List all files in a GCS Bucket from Vertex Notebook
from google.cloud import storage
bucket_name = "bucket_name"
prefix = "path/to/folder/"
# Initialize the GCS client
storage_client = storage.Client()
# Get a reference to the bucket
bucket = storage_client.get_bucket(bucket_name)
# List files in the bucket with the given prefix
blobs = bucket.list_blobs(prefix=prefix)
files = [blob.name for blob in blobs]
print(files)
Conclusion
This way, you can List all files in a GCS Bucket from Vertex Notebook.
Listing all files in a GCS Bucket from a Vertex Notebook is a straightforward…