使用列表文件剪切特定文件并将其移动到另一个目录

2024-04-30 00:29:17 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码

import os
import shutil
x_file = open(os.path.join('C:\\Users\\_\\Pictures\\Saved Pictures\\Part 7 Sketches', "output.txt"), "r")  
for image in x_file:
    v=str.strip(image)
    shutil.move('C:\\Users\\_\\Pictures\\Saved Pictures\\Part 7 Sketches\\'+v, 'C:\\Users\\_\\Pictures\\New')   

我想使用列表文件(输出文本)搜索目录,并将选定的图片移动到一个新目录。当我这样做的时候,我得到了一个错误前沿

with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\_\\Pictures\\Saved Pictures\\Part 7 Sketches\\001'

但是文件存在。。。感谢您的帮助


Tags: 文件pathimageimport目录密码osopen