首页 > 解决方案 > 使用python将文件从一个位置移动到另一个位置

问题描述

如何使用 python 将文件复制到目录中。我的所有 AB.jpg 都应复制到一个文件夹,而 BC.jpg 文件应复制到另一个文件夹,方法是使用文件路径中的日期对文件进行子脚本编写)。我创建的路径是基于时间戳动态的。

我的本地目录路径格式如下:

directory : /tmp/hash/inputsrc/20201229/....../AB.jpg
            /tmp/hash/inputsrc/20201228/....../BC.jpg
            /tmp/hash/inputsrc/20201229/....../AB.jpg
            /tmp/hash/inputsrc/20201228/....../BC.jpg
Expected output:
           /newfolder/AB_20201229.jpg
           /newfolder/AB_20201228.jpg
           /newfolder/BC_20201229.jpg
           /newfolder/BC_20201228.jpg

标签: pythonfile-handling

解决方案


推荐阅读