Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
busque en cada uno de los cubos s3 y vea si existe la carpeta dada

Estoy tratando de obtener los archivos de carpetas específicas en s3 Buckets:

Tengo 4 cubos en s3 con los siguientes nombres:

 1 - 'PDF' 2 - 'TXT' 3 - 'PNG' 4 - 'JPG'

La estructura de carpetas para todos los cubos s3 se ve así:

 1- PDF/analysis/pdf-to-img/processed/files 2- TXT/report/processed/files 3- PNG/analysis/reports/png-to-txt/processed/files 4- JPG/jpg-to-txt/empty

Tengo que verificar si este prefijo de carpeta processed/files está presente en el depósito, y si está presente, leeré los archivos presentes en esos directorios, de lo contrario los ignoraré.


Código:

 buckets = ['PDF','TXT','PNG','JPG'] client = boto3.client('s3') for i in bucket: result = client.list_objects(Bucket=i,Prefix = 'processed/files', Delimiter='/') print(result)

Puedo ingresar a cada directorio si la estructura de carpetas es la misma, pero ¿cómo puedo manejar esto cuando la estructura de carpetas varía para cada depósito?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Este es quizás un proceso largo.

 buckets = ['PDF','TXT','PNG','JPG'] s3_client = getclient('s3') for i in buckets: result = s3_client.list_objects(Bucket= i, Prefix='', Delimiter ='') contents = result.get('Contents') for content in contents: if 'processed/files/' in content.get('Key'): print("Do the process")

Puede obtener la lista de directorios del depósito s3. Si contiene la carpeta requerida, realice el proceso requerido.

over 4 years ago · Santiago Trujillo Report

0

import boto3 client = boto3.client('s3') bucket_name = "bucket_name" prefix = "" s3 = boto3.client("s3") result = client.list_objects(Bucket=bucket_name, Delimiter='/') for obj in result.get('CommonPrefixes'): prefix = obj.get('Prefix') file_list = ListFiles(client,bucket_name,prefix) for file in file_list: if "processed/files" in file: print("Found",file) def ListFiles(client, bucket_name, prefix): _BUCKET_NAME = bucket_name _PREFIX = prefix """List files in specific S3 URL""" response = client.list_objects(Bucket=_BUCKET_NAME, Prefix=_PREFIX) for content in response.get('Contents', []): #print(content) yield content.get('Key') 

ingrese la descripción de la imagen aquí ] 1

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!