在Python中使用os.walk进行迭代,但未返回预期的值

2024-06-25 23:08:40 发布

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

我是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”时,脚本运行时没有错误,但不返回任何内容


Tags: pathnamein目录密码forosfiles