Permission Denied On Shutil.move On Image Files
I am trying to move some files around. I can move any extension type except .png, .jpg, or .gif. When I try to move those types of files I get 'IOError: [Errno 13] Permission denie
Solution 1:
First things first, you're double escaping your dir
variable:
print(r'C:\\Users\\jcan4\\Desktop\\testmove\\*')
# Yields 'C:\\\\Users\\\\jcan4\\\\Desktop\\\\testmove\\\\*' !!# What you really meant was either one of the following:
dir_harderToRead = 'C:\\Users\\jcan4\\Desktop\\testmove\\*'
dir_easyToRead = r'C:\Users\jcan4\Desktop\testmove\*'
If you are still experiencing the error, it's because you are not giving the python script permissions to move the file. There are a couple ways to get around this:
Windows
(This applies to the asked question)
Open command prompt (I see your file path and am assuming you're on windows) with administrative rights. (see here)
Change ownership of the images to you. (see here for windows 10 or here for windows 7)
Linux (MacOS)
(This applies to people on Linux that may have the same problem)
- Run the python script with root privileges:
# At command line
sudo python your_script_name.py
- Change ownership of file to yourself:
# At command line# Changes ownership of entire directory (CAREFUL):chmod 755 /absolute/path/to/dir
chmod 755 relative/path/to/dir
# Or you can change file by file:chmod 755 /absolute/path/to/file
chmod 755 relative/path/to/file
For more info, I used this site on permissions. (If someone has a numerical value than 755
for chmod please say so.)
Post a Comment for "Permission Denied On Shutil.move On Image Files"