Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python递归地搜索目录中是否存在路径?_Python_File - Fatal编程技术网

如何使用python递归地搜索目录中是否存在路径?

如何使用python递归地搜索目录中是否存在路径?,python,file,Python,File,您好,我想知道目录中是否存在递归路径。 我写了一个剧本,但是太慢了。 所以我想知道还有其他的方法。 “路径”是完整路径的部分字符串 bMatch = False for dirpath, dirnames, filenames in os.walk("."): for f in filenames : full_path = os.path.join(dirpath, f) logger.error(full_pat

您好,我想知道目录中是否存在递归路径。 我写了一个剧本,但是太慢了。 所以我想知道还有其他的方法。 “路径”是完整路径的部分字符串

    bMatch = False
    for dirpath, dirnames, filenames in os.walk("."):
        for f in filenames :
            full_path = os.path.join(dirpath, f)
            logger.error(full_path)
            if path in full_path :
                bMatch = True
                logger.error("Matched")
                break
        if bMatch == True :
            break
    if bMatch == False :
        logger.error("[Error] Path doesn't exist. Please check " + path + ' in the row ' + str(row + 1))

您可以使用
os.listdir
并将op存储到
队列中
。然后您可以验证路径。请参阅我的,以了解如何过滤隐藏和可见的目录和文件。您将了解如何在那里处理文件和目录。

您使用的软件包是什么,变量
path
从何而来。。。当您说“路径是一个部分字符串”时,请阅读,您的意思是它是某个父文件夹,还是将
c:\ag
作为
c:\agnes
的部分字符串?