0

I want to copy all the pictures from one folder to another folder. I tried to run this code again and again but it returns me False only instead of saving pictures to other folder.

import cv2
import glob
input_path = 'C:\\Users\\Kazmi-PC\\OneDrive\\Pictures\\1\\*.*'
output_path = 'C:\\Users\\Kazmi-PC\\OneDrive\\Pictures\\2\\*.jpg'
for file in glob.glob(input_path):
   print("printing.....")
   print(file)
   a= cv2.imread(file)
cv2.imwrite(output_path, a)
2
  • you can't use * in output. You have to run imwrite inside for loop. And you have to use real, unique name for every file. Commented Jul 20, 2019 at 16:23
  • 1
    if you want to copy files then you can use shutil.copy(input_name, output_name) but you still have to copy every file separatelly. But you can use directory as output and then it will use filename from input. Commented Jul 20, 2019 at 16:28

1 Answer 1

2

You can't use * in output filename. You would have to use imwrite inside for loop and use unique filenames in output.


You can use shutil.copy(file, directory) to copy. So you can use output without *.jpg and you don't have to add filename in output.

But you still need to copy every file separatelly.

import glob
import shutil

input_path = 'C:\\Users\\Kazmi-PC\\OneDrive\\Pictures\\1\\*.*'
output_dir = 'C:\\Users\\Kazmi-PC\\OneDrive\\Pictures\\2\\'

for file in glob.glob(input_path):
   shutil.copy(file, output_dir)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.