This is not this question: Rename script with [Errno2] No such file or directory
I am trying to move the images from the folder images to train_images and test_images folders on the basis of corresponding xml file names in train and test folders. But getting this error consistently: 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'
My script is:
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)
Thanks in Advance!
I found the mistake.
Solution:
The code did worked
Thank You!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.