首页 > 解决方案 > 如何将文件创建/修改文件复制到新文件

问题描述

文件创建/修改时间有重要信息。在将文件转换为新文件(例如视频)时,如何在 Python 中保留创建/修改时间。就像是:

# pseudo code
old_time = original_video.gettime()

# new_video and original_video are totally different files.
new_video = create_and_convert(original_video)

# How to copy old file create/modify time to new file?
set_time(new_video, old_time)

我希望 new_video 具有完全相同的创建/修改时间。怎么做?

标签: pythonfile

解决方案


为您的用例使用时间模块。

import time
old_time = time.ctime()

推荐阅读