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
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 272 May-03-2024, 07:23 AM
Last Post: Pedroski55
  What does .flush do? How can I change this to write to the file? Pedroski55 3 300 Apr-22-2024, 01:15 PM
Last Post: snippsat
  write code that resides in parent directory franklin97355 3 489 Apr-14-2024, 02:03 AM
Last Post: franklin97355
  Last record in file doesn't write to newline gonksoup 3 494 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  KivyMD android app - problem with permission polak7gt 0 333 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 625 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Recommended way to read/create PDF file? Winfried 3 2,972 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  write to csv file problem jacksfrustration 11 1,653 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,604 Nov-09-2023, 10:56 AM
Last Post: mg24
  Potential Permission error on Mac OSX Catalina OWOLLC 1 774 Nov-02-2023, 07:52 AM
Last Post: unjnsacih

Forum Jump:

User Panel Messages

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