My understanding is that, in order to delete a file, I need write permission to the parent folder (for Windows). I don't need write permission to the file itself.
But os.remove gives me "[WinError 5] Access is denied". I can delete that file via the Windows explorer with my user.
shutil.copy copies a file to a folder without problems, but running the script again gives a "[Errno 13] Permission denied", because the file is read-only and can not be overwritten. It makes no sense that I can create files but not delete those afterwards. Fix is to use shutil.copyfile, because then the destination file has no permissions and it can be overwritten in the next run, but then this won't work if the file already exists with the permissions.
How do I delete a file with only read permissions but write permission to the parent folder?
Python 3.3.2
read-only attribute can be cleared like this.
import os
import stat
os.chmod(filePath, stat.S_IWRITE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With