0

This is a simple copy file problem and I came here with my solution. There are some questions in Stackoverflow that are not closed as my problem. That's why I opened this.

Explanation:

Python gives errors while copying files, in my case I tried to copy the image data set to another file(318MB). Python gives these errors in random sequence.

Data Set: Data
Python Version: 3.8.13
IDE: VSCode

Code and Error Message:

for jpgfile in glob.iglob(os.path.join(imageData, "*.jpeg")):
   shutil.copy(jpgfile, dst_dir)

C:/Users/user1/Desktop/imageData Traceback (most recent call last):
File "c:\Users\user1\Desktop\copyImageJPEG.py", line 35, in shutil.copy(jpgfile, dst_dir) File "C:\Users\user1\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 418, in copy copyfile(src, dst, follow_symlinks=follow_symlinks) File "C:\Users\user1\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 264, in copyfile with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst: PermissionError: [Errno 13] Permission denied: 'C:/Users/user1/Desktop/copyFolder\person110_virus_207.jpeg'

What I've done till now,

  1. Gave permission access with chmod

  2. Tried to copy , copyFile, copy2 functions

Also this ref.

  1. Wrote full path for both source and destination

  2. Encoded the path for both source and destination

  3. Run the python code as Admin

Also this ref.

  1. r-prefix

Those solutions did not work for my problem. For those who can't find a solution like me, here is another solution:

Just close the copyFolder, don't disrupt it. In my case, I got the error while trying to see the last copied image, so the error popped up 50th, 100th, 150th, etc., depending on my check time. Somehow the operating system blocks the code while we are using the folder.

I will update this post if I get another solution or the real reason for this disruption.

Edit: @Barmar Windows locks files while they're open in an editor. You get an error if you try to overwrite the locked file.

OJazz
  • 1
  • 1

0 Answers0