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
#5
In case someone is interested in my solution for copying a file and overwriting it in case it is already available:

import os
import shutil
import filecmp
import stat

def copyFile(sourceFile, destinationFile):
  if not os.path.isfile(destinationFile) or not filecmp.cmp(sourceFile, destinationFile):
    if os.path.isfile(destinationFile):
      os.chmod(destinationFile, stat.S_IWRITE) # Make sure the file is not read-only
    shutil.copyfile(sourceFile, destinationFile)
Reply


Messages In This Thread
RE: Delete file with read-only permission, but write permission to parent folder - by cubei - Aug-28-2018, 09:40 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 243 Apr-22-2024, 01:15 PM
Last Post: snippsat
  write code that resides in parent directory franklin97355 3 423 Apr-14-2024, 02:03 AM
Last Post: franklin97355
  Last record in file doesn't write to newline gonksoup 3 456 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  KivyMD android app - problem with permission polak7gt 0 303 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 570 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Recommended way to read/create PDF file? Winfried 3 2,907 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  write to csv file problem jacksfrustration 11 1,562 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,480 Nov-09-2023, 10:56 AM
Last Post: mg24
  Potential Permission error on Mac OSX Catalina OWOLLC 1 732 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
Question Special Characters read-write Prisonfeed 1 635 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