1

I am trying to write this program to read through directories into the file and read the first line of the file. If it finds certain keywords to then re name the file, copy the file, and more it to a corresponding directory.

import os
import shutil
import sys

os.chdir('c:\\source')

sourcePattern = '2:I103'
targetDirMt = 'mt'
targetDirF21 = 'F21'


curFile = open(os.path.abspath(os.curdir) + '\\' +'ack_nak', 'r+')

for line in fileinput.input ( curFile ):     #(os.curdir, 'r+')
    if sourcePattern in curFile :
        os.rename(file, '2:I103-'+file)

    if targetDirMt in curFile :
        shutil.move(file,'C:\\target\\mt')

    if targetDirF21 in curFile :
        shutil.move(file,'C:\\target\\F21')

Why do I get this??

Traceback (most recent call last):
  File "C:\Python34\project1.py", line 12, in <module>
    curFile = open(os.path.abspath(os.curdir) + '\\' +'ack_nak', 'r+')
PermissionError: [Errno 13] Permission denied: 'c:\\source\\ack_nak'

1 Answers1

-1

Try using super user (sudo) command. Lack of permissions is generally remedied by this. It will however prompt you for username and password, so you might have to work around that.

IOError: 13, 'Permission denied' when writing to /etc/hosts via Python - Read the answers here, they explain the code needed.

Open a file as superuser in python - This is some more in depth information.

Good luck.

Community
  • 1
  • 1
Ian
  • 675
  • 1
  • 9
  • 25
  • From the user's error message it is evident that he is running on Windows, not UNIX/Linux/POSIX. – Robᵩ Jun 22 '15 at 15:33
  • @Rob Did you look at the second link and the first answer? It explains in depth how to do a similar operation (run as admin) in Windows that solves the same problem. Please look at the links before you downvote. Thanks. – Ian Jun 22 '15 at 15:41