Move files from subfolders to another folder

Viewed 36

I want to move all the files from multiple subdirectories to another folder in the same directory as the parent folder but get the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Dev/FaceRec/lfw/Emmit_Smith/Emmit_Smith_0001.jpg' -> '/content/drive/MyDrive/Dev/FaceRec/negatives/Emmit_Smith_0001.jpg'

this is my code:

for directory in os.listdir('/content/drive/MyDrive/Dev/FaceRec/lfw'):
  for file in os.listdir(os.path.join('/content/drive/MyDrive/Dev/FaceRec/lfw', directory)):
    path = os.path.join('/content/drive/MyDrive/Dev/FaceRec/lfw', directory, file)
    new_path = os.path.join('/content/drive/MyDrive/Dev/FaceRec/negatives', file)
    os.replace(path, new_path)

Thank you for the help in advance

0 Answers
Related