[英]PermissionError Errno 13 Permission denied
I am trying to read a directory which contains html files with python. 我正在尝试使用python读取包含html文件的目录。 The code I am using is this:
我正在使用的代码是这样的:
import os
f = open(r"C:\Users\Grty\Desktop\de", "w+")
for filename in os.listdir(os.getcwd()):
content = f.read()
print (filename, len(content))
The problem is I cant access the directory. 问题是我无法访问目录。 I have tried different locations but the problem persists.
我尝试过其他位置,但问题仍然存在。 I have also done the relative chmod 777 (Using windows 10) and still nothing.
我也做了相对的chmod 777(使用Windows 10),却一无所获。 I enabled sharing with everyone, giving read/write permissions to everyone and also disabled the "read only" (which somehow is being re-enabled itself).
我启用了与所有人共享的权限,为所有人提供了读/写权限,还禁用了“只读”(本身已在某种程度上被重新启用)。 I have also run the cmd as an admin and still no progress.
我也已经以管理员身份运行cmd,但仍然没有任何进展。 Anyone got an idea of how to overcome this?
任何人都知道如何克服这一点?
You are trying to open a folder for writing: 您正在尝试打开一个文件夹进行写入:
f = open(r"C:\Users\Grty\Desktop\de", "w+")
But this is a folder, which can't be opened using open()
even in "r"
mode, because it isn't a file, and if you try, Windows will say access denied . 但这是一个文件夹,即使在
"r"
模式下也无法使用open()
打开该文件夹,因为它不是文件,并且如果尝试这样做,Windows会说访问被拒绝 。 As you get each filename
, open that: 获得每个
filename
,打开该filename
:
for filename in os.listdir(os.getcwd()):
with open(filename) as f:
content = f.read()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.