Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List directories in amazon S3 with AWS SDK

Tags:

amazon-s3

I am trying to list folders in S3:

string delimiter = "/";
folder = "a/";
ListObjectsResponse r = s3Client.ListObjects(new Amazon.S3.Model.ListObjectsRequest()
{
  BucketName = BucketName,
  Prefix = folder, 
  MaxKeys = 1000,
  Delimiter = delimiter
});

and i expect list of directories such as:

a/Folder1
a/Folder2
....
a/FolderN

but my actual result is only 1 object: 'a1'

like image 941
st78 Avatar asked Jan 29 '11 14:01

st78


People also ask

Does AWS S3 have folders?

In Amazon S3, folders are used to group objects and organize files. Unlike a traditional file system, Amazon S3 doesn't use hierarchy to organize its objects and files. Amazon S3 console supports the folder concept only as a means of grouping (and displaying) objects.

How do you list items in a bucket?

List Objects. To get a list of objects within a bucket, use the AmazonS3 client's listObjects method, supplying the name of a bucket. The listObjects method returns an ObjectListing object that provides information about the objects in the bucket.

What is directory in S3?

Directories don't actually exist within S3 buckets. The entire file structure is actually just one flat single-level container of files. The illusion of directories are actually created based on naming the files names like dirA/dirB/file .


1 Answers

Folders are not treated as objects in S3.

Instead, I need to read string[] CommonPrefixes property, which has my subfolders

like image 183
st78 Avatar answered Nov 15 '22 06:11

st78