-1

I have compiled a small rename program using py2exe. Whenever I run the executable I receive the following error: "Line 17, in WindowsError: [Error 5] Access is denied". The program runs fine in the python interrupter, but does not work as an EXE. I have tried running the executable with admin rights but I have gotten the same results. Below is line 17, does anyone know why this is occurring? Thanks.

for filename in filenames: 
    os.rename(os.path.join(path, filename), os.path.join(path, filename.replace(cur_Name, new_Name))) 
MRG123
  • 123
  • 3
  • 12
  • Are you running antivirus software? See http://stackoverflow.com/a/21884736/245915 – nofinator Jul 31 '14 at 15:00
  • Yes, mcafee for work. It's mandatory and cannot be removed per I.T....is there a way around this? Or an alternative method of renaming files with python, so that it doesn't conflict with an antivirus software? – MRG123 Jul 31 '14 at 15:02
  • one thing you can try is seeing if you can add your executable to the exclusion list of your antivirus. – James Kent Jul 31 '14 at 15:04
  • @JamesKent, adding it to the exclusions list provided the same results. – MRG123 Jul 31 '14 at 15:11
  • @MRG123 I'm not sure about with mcafee, but with my antivirus i can access a log of its actions, can you find a log and check if it is mcafee blocking it? – James Kent Jul 31 '14 at 15:14
  • @JamesKent I accessed the log and see no evidence of mcafee blocking it. Thanks for the advice though, I'm sure there's a way to get this to run. – MRG123 Jul 31 '14 at 16:18

1 Answers1

1

I had this recently when I tried to delete a bunch of files and the first one was a Read Only file. I just right clicked it and ticked off "Read Only". This solved my error.

Just out of interest, here is my program:

#This matches (1) files and deletes them IF there is an original of the same file size.

import os

path = "e:\\"

for root, dirs, files in os.walk(path):
        for lastfile in files:
                if lastfile.find(' (1).') > -1:
                        onepos = lastfile.find(' (1).')
                        for thisfile in files:
                                matcherone = (lastfile[0:onepos] + lastfile[onepos+4:len(lastfile)])
                                if matcherone == thisfile:
                                        lastfilesize = os.path.getsize(os.path.join(root,lastfile));
                                        thisfilesize = os.path.getsize(os.path.join(root,thisfile));
                                        if lastfilesize-thisfilesize == 0:
                                                print "Deleting : ", os.path.join(root,lastfile);
                                                os.remove(os.path.join(root,lastfile));