以下是使用Python实现获取文件夹最新文件日期的示例代码:

import os
import datetime

def get_latest_file_date(folder_path):
    # 获取文件夹中所有文件的修改时间
    file_dates = [os.path.getmtime(os.path.join(folder_path, file)) for file in os.listdir(folder_path)]

    # 找到最新的修改时间
    latest_date = max(file_dates)

    # 将时间戳转换为日期格式
    latest_file_date = str(datetime.datetime.fromtimestamp(latest_date).date())

    return latest_file_date

使用示例:

folder_path = '/path/to/folder'
latest_file_date = get_latest_file_date(folder_path)
print('最新文件日期为:', latest_file_date)

注意:需要导入datetime模块。

Python 获取文件夹最新文件日期

原文地址: https://www.cveoy.top/t/topic/otpp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录