C# List all files with filename under a amazon S3 folder

0 votes

Using C# and amazon .Net SDK,able to list all the files with in a amazon S3 folder as below:

ListObjectsRequest request = new ListObjectsRequest();           
            request.BucketName = _bucketName; //Amazon Bucket Name
            request.Prefix = _sourceKey; //Amazon S3 Folder path           
            do
            {
                ListObjectsResponse response = _client.ListObjects(request);//_client - AmazonS3Client

Out put:

    Folder
    Folder/file1.pdf
    Folder/file2.pdf
    Folder/file3.pdf

But i wanted to achieve something like this: Desired Output:

file1.pdf
file2.pdf
file3.pdf

Thanks in advance

Oct 5, 2018 in AWS by eatcodesleeprepeat
• 4,670 points
4,328 views

1 answer to this question.

0 votes

Also you can use the following c# code to retrieve the files information.

    string bucketName = "your bucket";
    AmazonS3Client s3Client = new AmazonS3Client("your access key", "your secret key", cfg);
    S3DirectoryInfo dir = new S3DirectoryInfo(s3Client, bucketName, "your AmazonS3 folder name");
    foreach (IS3FileSystemInfo file in dir.GetFileSystemInfos())
    {
        Console.WriteLine(file.Name);
        Console.WriteLine(file.Extension);
        Console.WriteLine(file.LastWriteTime);
    }

I am using amazon AWSSDK.Core and AWSSDK.S3 version 3.1.0.0 for .net 3.5. I hope it can help you

answered Oct 5, 2018 by Priyaj
• 56,920 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
2,800 views
0 votes
1 answer

How to list all the objects in Amazon S3?

As stated already, Amazon S3 indeed requires ...READ MORE

answered Oct 5, 2018 in AWS by Archana
• 4,090 points
544 views
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 56,920 points
298 views
0 votes
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 56,920 points
673 views
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,560 points
472 views
0 votes
2 answers
+3 votes
5 answers

How to move files from amazon ec2 to s3 bucket using command line

Hey, 3 ways you can do this: To ...READ MORE

answered Oct 9, 2018 in AWS by Omkar
• 67,660 points
3,924 views