Python Forum
Delete file with read-only permission, but write permission to parent folder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete file with read-only permission, but write permission to parent folder
#1
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
Reply


Messages In This Thread
Delete file with read-only permission, but write permission to parent folder - by cubei - Aug-27-2018, 08:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What does .flush do? How can I change this to write to the file? Pedroski55 3 212 Apr-22-2024, 01:15 PM
Last Post: snippsat
  write code that resides in parent directory franklin97355 3 407 Apr-14-2024, 02:03 AM
Last Post: franklin97355
  Last record in file doesn't write to newline gonksoup 3 437 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  KivyMD android app - problem with permission polak7gt 0 296 Jan-18-2024, 01:27 PM
Last Post: polak7gt
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 558 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Recommended way to read/create PDF file? Winfried 3 2,899 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  write to csv file problem jacksfrustration 11 1,547 Nov-09-2023, 01:56 PM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,468 Nov-09-2023, 10:56 AM
Last Post: mg24
  Potential Permission error on Mac OSX Catalina OWOLLC 1 723 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
Question Special Characters read-write Prisonfeed 1 628 Sep-17-2023, 08:26 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020