如何改进在 Python 中移动所有不包含特定日期的文件?

我想移动所有不以今天开始的文件,我的代码如下,我可以更快地改进它吗?


today = datetime.datetime.today().strftime('%Y%m%d')

all_files = os.listdir(image_current_path)

for i, image_file in enumerate(all_files):

    if not image_file.startswith(today):

        image_file = os.path.join(image_current_folder, image_file) # added

        shutil.move(image_file, image_old_path)


catspeake
浏览 141回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python