简体   繁体   English

如何使用 python 从 S3 获取最新的文件夹路径

[英]How to get latest folder path from S3 using python

I have multiple s3 file paths which contain the folder name as date.我有多个 s3 文件路径,其中包含文件夹名称作为日期。 I want to extract the latest path from S3 using python and boto3 based on the date.我想根据日期使用 python 和 boto3 从 S3 中提取最新路径。

For Example- Below are the few paths I have under my root folder(s3:///all/stage/servicenow/service-mgmt/sm_task/raw/) Sample Paths -例如-以下是我的根文件夹下的几个路径(s3:///all/stage/servicenow/service-mgmt/sm_task/raw/)示例路径-

  1. s3://my-bucket/all/stage/pqr/xyz/abc/raw/2020/12/11/10/20/file.parquet s3://my-bucket/all/stage/pqr/xyz/abc/raw/2020/12/11/10/20/file.parquet
  2. s3://my-bucket/all/stage/pqr/xyz/abc/raw/2020/12/11/11/12/file.parquet s3://my-bucket/all/stage/pqr/xyz/abc/raw/2020/12/11/11/12/file.parquet
  3. s3://my-bucket/all/stage/pqr/xyz/abc/raw/2020/12/11/12/01/file.parquet s3://my-bucket/all/stage/pqr/xyz/abc/raw/2020/12/11/12/01/file.parquet
  4. s3://my-bucket/all/stage/pqr/xyz/abc/raw/2020/12/12/11/10/file.parquet s3://my-bucket/all/stage/pqr/xyz/abc/raw/2020/12/12/11/10/file.parquet

all the above paths are in s3:///all/stage/pqr/xyz/abc/raw/YYYY/MM/DD/HH/mm/file.parquet format以上所有路径均采用 s3:///all/stage/pqr/xyz/abc/raw/YYYY/MM/DD/HH/mm/file.parquet 格式

So I need the latest timestamp path under root path (s3:///all/stage/pqr/xyz/abc/raw/) which is s3:///all/stage/pqr/xyz/abc/raw/2020/12/12/11/10/file.parquet.所以我需要根路径(s3:///all/stage/pqr/xyz/abc/raw/)下的最新时间戳路径,即 s3:///all/stage/pqr/xyz/abc/raw/2020/ 12/12/11/10/file.parquet。

How can i achieve this using python and Boto3.我如何使用 python 和 Boto3 来实现这一点。

Any help will be appreciated as I am new in python任何帮助将不胜感激,因为我是 python 的新手

Please comment if the question is not clear如果问题不清楚,请发表评论

from os import path

is one way to check the file using function是使用 function 检查文件的一种方法

os.path.splitext(root,date)

and just use your own algorithm to check weather or not your file time is the newest并且只需使用您自己的算法来检查天气或您的文件时间是否是最新的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python 中的 boto3 从 S3 文件夹下载最新文件? - How to download latest file from S3 folder using boto3 in python? 如何使用 python 列出 S3 存储桶文件夹中的文件 - how to list files from a S3 bucket folder using python 如何仅从 S3 存储桶中的特定路径文件夹(或路径前缀)获取文件 - How to get only files only from specific path folder (or path prefix) in an S3 bucket 如何使用Python获取目录中的最新文件夹 - How to get the latest folder in a directory using Python 如何使用Boto Python从S3获取最新文件的最后修改日期? - How to get last modified date of latest file from S3 with Boto Python? 如何使用 pyspark 从 S3 存储桶中的最新文件中获取日期 - How to get the date from the latest file in the S3 bucket using pyspark 如何使用事件触发的lambda从S3存储桶获取最新的文件名或文件 - How to get latest file-name or file from S3 bucket using event triggered lambda 如何使用 boto3 将文件从 S3 下载到自定义文件夹或网络路径 - How to download files from S3 to a custom folder or a network path using boto3 如何使用python获取最新创建的文件名而不是文件夹名? - How to get the latest created file name and not the folder name using python? 如何使用 python 从 s3 读取按日期文件夹分区的镶木地板文件? - How to read parquet file partitioned by date folder from s3 using python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM