Question: I'm going to write a Python program to check if a file is in certain folder of my Google Cloud Storage, the basic idea is to get the `list` of all objects in a folder, a file name `list`, then check if the file `abc.txt` is in the file name `list`.

Now the problem is, it looks Google only provide the one way to get `obj` `list`, which is `uri.get_bucket()`, see below code which is from <https://developers.google.com/storage/docs/gspythonlibrary#listing-objects>

```
uri = boto.storage_uri(DOGS_BUCKET, GOOGLE_STORAGE)
for obj in uri.get_bucket():
    print '%s://%s/%s' % (uri.scheme, uri.bucket_name, obj.name)
    print '  "%s"' % obj.get_contents_as_string()

```

The defect of `uri.get_bucket()` is, it looks it is getting all of the object first, this is what I don't want, I just need get the `obj` name `list` of particular folder(e.g `gs//mybucket/abc/myfolder`) , which should be much quickly.

Could someone help answer? Appreciate every answer!

Answer: 
You might also want to look at [gcloud-python](https://github.com/GoogleCloudPlatform/gcloud-python) and [documentation](http://googlecloudplatform.github.io/gcloud-python/storage-api.html#gcloud.storage.bucket.Bucket.get_all_keys).

```
from gcloud import storage
connection = storage.get_connection(project_name, email, private_key_path)
bucket = connection.get_bucket('my-bucket')

for key in bucket:
  if key.name == 'abc.txt':
    print 'Found it!'
    break

```

However, you might be better off just checking if the file exists:

```
if 'abc.txt' in bucket:
  print 'Found it!'

```
I know this is an old question, but I stumbled over this because I was looking for the exact same answer. Answers from Brandon Yarbrough and Abhijit worked for me, but I wanted to get into more detail.

When you run this:

```
from google.cloud import storage
storage_client = storage.Client()
blobs = list(storage_client.list_blobs(bucket_name, prefix=PREFIX, fields="items(name)"))

```

You will get Blob objects, with just the name field of all files in the given bucket, like this:

```
[<Blob: BUCKET_NAME, PREFIX, None>, 
 <Blob: xml-BUCKET_NAME, [PREFIX]claim_757325.json, None>, 
 <Blob: xml-BUCKET_NAME, [PREFIX]claim_757390.json, None>,
 ...]

```

If you are like me and you want to 1) filter out the first item in the list because it does NOT represent a file - its just the prefix, 2) just get the name string value, and 3) remove the PREFIX from the file name, you can do something like this:

```
blob_names = [blob_name.name[len(PREFIX):] for blob_name in blobs if blob_name.name != folder_name]

```

Complete code to get just the string files names from a storage bucket:

```
from google.cloud import storage
storage_client = storage.Client()
blobs = list(storage_client.list_blobs(bucket_name, prefix=PREFIX, fields="items(name)"))
blob_names = [blob_name.name[len(PREFIX):] for blob_name in blobs if blob_name.name != folder_name]
print(f"blob_names = {blob_names}")

```