繁体   English   中英

使用os.walk在python中迭代未返回期望值

[英]Iterating in python with os.walk not returning the expected values

我是python的新手,我一直在尝试遍历包含大量具有一定深度的子目录的大目录。

直到现在,我直到这段代码。

for dirpath, subdirs, files in os.walk("//media//rayeus//Datos//Mis  Documentos//Nueva Carpeta//", topdown=True):
   for name in files:
      f = os.path.join(dirpath, name)
      print f

   for name in subdirs:
      j = os.path.join(dirpath, name)
      print j

想法是使用迭代在目录内结构的excel文件中进行清单清点。

问题是,如果我只留下相同的路径而没有“ Nueva carpeta”,则可以正常工作...但是当我添加“ Nueva Carpeta”时,脚本运行无错误,但不返回任何内容

import os

def crawl(*args, **kw):
    '''
    This will yield all files in all subdirs
    '''
    for root, _, files in os.walk(*args, **kw):
        for fname in files:
            yield os.path.join(root, fname)


for fpath in crawl('.', topdown=1):
    print fpath

暂无
暂无

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

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