· 7 years ago · Jun 22, 2018, 05:30 PM
1temp/
2 temp/foobar.txt
3 temp/txt/
4 temp/txt/test1.txt
5 temp/txt/test2.txt
6 temp2/
7
8IAmazonS3 client;
9using (client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1))
10{
11 // Build your request to list objects in the bucket
12 ListObjectsRequest request = new ListObjectsRequest
13 {
14 BucketName = "MyBucketName"
15 };
16
17 do
18 {
19 // Build your call out to S3 and store the response
20 ListObjectsResponse response = client.ListObjects(request);
21
22 // Filter through the response to find keys that:
23 // - end with the delimiter character '/'
24 // - are empty.
25 IEnumerable<S3Object> folders = response.S3Objects.Where(x =>
26 x.Key.EndsWith(@"/") && x.Size == 0);
27
28 // Do something with your output keys. For this example, we write to the console.
29 folders.ToList().ForEach(x => System.Console.WriteLine(x.Key));
30
31 // If the response is truncated, we'll make another request
32 // and pull the next batch of keys
33 if (response.IsTruncated)
34 {
35 request.Marker = response.NextMarker;
36 }
37 else
38 {
39 request = null;
40 }
41 } while (request != null);
42}
43
44temp/
45temp/txt/
46temp2/
47
48ListObjectsRequest request = new ListObjectsRequest
49 {
50 BucketName = "MyBucketName",
51 Prefix = "temp/"
52 };
53
54temp/
55temp/txt/
56
57using System;
58using System.Collections.Generic;
59using System.Linq;
60using System.Text;
61using System.Threading.Tasks;
62
63using Minio;
64using Minio.Xml;
65
66namespace Minio.Examples
67{
68 class ListObjects
69 {
70 static int Main(string[] args)
71 {
72 var client = new MinioClient("https://s3.amazonaws.com", "ACCESSKEY", "SECRETKEY");
73
74 var items = client.ListObjects("bucket");
75
76 foreach (Item item in items)
77 {
78 if (item.IsDir)
79 {
80 Console.Out.WriteLine("{0}", item.Key);
81 }
82 }
83 return 0;
84 }
85 }
86}