简体   繁体   English

Errno 13许可被拒绝:?

[英]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. 尝试使用超级用户(sudo)命令。 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. IOError:13,通过Python写入/ etc / hosts时,“权限被拒绝” -在此处阅读答案,它们解释了所需的代码。

Open a file as superuser in python - This is some more in depth information. 在python中以超级用户身份打开文件 -这是更深入的信息。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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