FileNotFoundError:[WinError 2]系统找不到指定的文件:“demo.html”

2024-05-14 16:44:30 发布

您现在位置:Python中文网/ 问答频道 /正文

这是代码

import os,stat
from os import walk

path = "C:/Users/HP/Desktop"    
owner = "DEEPTHI\HP"

for root, dirs, files in walk(path, topdown=False):  
    for f in files:  
        if os.stat(f).st_uid == owner:
            print(f)

运行它之后,我收到一个FileNotFoundError


Tags: path代码infromimportforosfiles
1条回答
网友
1楼 · 发布于 2024-05-14 16:44:30

filesroot下的文件名列表,因为os.walkpath下遍历时找到了这些文件名

现在,仅通过它们的文件名而不使用路径的其余部分来访问它们相对于当前工作目录,并不能告诉os.stat如何(在哪里)访问这些文件。例如,您可以添加:

    for f in files:
        fullpath = os.path.join(path, root, f)

然后对stat使用fullpath或对这些文件执行任何其他操作

相关问题 更多 >

    热门问题