简体   繁体   中英

Errno 13 Permission denied:?

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM