I need to delete all files within a folder in Amazon S3 using Pyspark.This is the code
s3 = boto3.resource('s3')
bucket = s3.Bucket('sales')
boto3_prefix = "build/subdomains/sim/users/ongoing"
for objects in bucket.objects.filter(Prefix=boto3_prefix):
if objects.key != boto3_prefix:
del_response = bucket.objects.filter(Prefix=objects.key).delete()```
But it deletes the folder 'ongoing' alongwith all the files inside.
Is there a way to only delete the files within 'ongoing' folder
and not the folder itself