这不是这个问题:Rename script with [Errno2] No such file or directory
我正在尝试根据train和test文件夹中相应的xml文件名将图像从文件夹图像移动到train_images和test_images文件夹。
但是始终出现此错误:
Traceback (most recent call last):
File "Move2.py", line 13, in <module>
os.rename(src2,dest2)
FileNotFoundError: [Errno 2] No such file or directory: '/home/mohit/darkflow/yes/images/DSCN8434.jpg' -> '/home/mohit/darkflow/yes/train_images/DSCN8434.jpg'
我的脚本是:
import os
train=os.listdir("/home/mohit/darkflow/yes/train")
test=os.listdir("/home/mohit/darkflow/yes/test")
path2="/home/mohit/darkflow/yes/images/"
moveto3="/home/mohit/darkflow/yes/train_images/"
moveto4="/home/mohit/darkflow/yes/test_images/"
for f_name in train:
f_name=f_name.replace(".xml",".jpg")
src2=path2+f_name
dest2=moveto3+f_name
os.rename(src2,dest2)
for f_name2 in test:
f_name2=f_name2.replace(".xml",".jpg")
src2=path2+f_name2
dest=moveto4+f_name2
os.rename(src2,dest2)
预先感谢!
答案 0 :(得分:0)
我发现了错误。
解决方案:
代码确实有效
谢谢!