I am working on a program that would:
- Process a file
- If no error move into Processed Directory (using postSuccessActions below)
- If error move into Error Directory
Code:
def postSuccessActions(self, fileName):
basedir = os.path.dirname(fileName)
dest = os.path.join(os.path.dirname(fileName), 'Processed\\Original\\')
self._createPath(dest) #custom function that create only if path doesn't exist
shutil.move(fileName, dest)
Issue: The problem is that shutil.move creates a copy of the file in the destination folder and then tries to delete it but fails with error below:
WindowsError: [Error 5] Access is denied: '<filename here>'
Now I don't want to come this far if the user has no delete permission on the file being processed. I am looking for a way to check if a given file can be deleted before doing any processing with it. How do I do it with python on windows?