Boto3 get contents of S3 bucket
<p>I am trying to get the list of files in a subfolder of a bucket.  Everything works fine, except, when I try to parse the files I notice that the first key my code pulls is the subfolder name.  Is there any way to leave out the subfolder name as a key?</p>

<pre><code>s3 = session.resource('s3')
bucket = s3.Bucket('bucket_name')

for obj in bucket.objects.filter(Prefix="sub1"):
    key = obj.key
    print(key)
</code></pre>

<p>Results from print key</p>

<pre><code>sub1/
sub1/file1
sub1/file2
.
.
</code></pre>

<p>I'd imagine there is a <code>.exclude</code> on the collections like in django but i couldn't see it as an option. You could try something like this</p>

<pre><code>s3 = session.resource('s3')
bucket = s3.Bucket('bucket_name')
prefix = "sub1/"
data = [obj for obj in list(bucket.objects.filter(Prefix=prefix)) if obj.key != prefix]

for obj in data:
    print(obj.key)
</code></pre>

python amazon-s3 boto3