My python script executes an os.listdir(path) where the path is a queue containing archives that I need to treat one by one.

我的python脚本执行一个os.listdir(路径),其中路径是一个包含归档的队列,我需要逐一处理这些归档。

The problem is that I'm getting the list in an array and then I just do a simple array.pop(0). It was working fine until I put the project in subversion. Now I get the .svn folder in my array and of course it makes my application crash.

问题是,我在数组中获取列表,然后做一个简单的array.pop(0)在我把这个项目放到subversion中之前,它一直运行得很好。现在我在数组中得到了。svn文件夹,当然这会导致应用程序崩溃。

So here is my question: is there an existing function that ignore hidden files when executing an os.listdir() and if not what would be the best way?

因此,我的问题是:是否存在在执行os.listdir()时忽略隐藏文件的现有函数,如果没有,最好的方法是什么?

Thank you.

谢谢你!

7 个解决方案

#1


65

You can write one yourself:

你可以自己写一个:

def listdir_nohidden(path):    for f in os.listdir(path):        if not f.startswith('.'):            yield f

Or you can use a glob:

或者你也可以使用glob:

def listdir_nohidden(path):    return glob.glob(os.path.join(path, '*'))

Either of these will ignore all filenames beginning with '.'.

其中任何一个都将忽略从“.”开始的所有文件名。

更多相关文章

  1. Gunicorn + Django + Heroku。Python的路径问题
  2. py2exe使用相对路径的当前目录问题
  3. tensorflow 变量定义路径//问题
  4. python在windows中的文件路径问题
  5. Python添加默认模块搜索包路径
  6. 《数据结构与算法Python语言描述》裘宗燕 笔记 第五章 栈和队列
  7. 如何获得正在运行的Python脚本的路径?(复制)
  8. 多队列网卡CPU中断均衡
  9. 如何在Linux中以编程方式获取给定相对路径的绝对路径?

随机推荐

  1. 我需要从jquery ajax post中撤回数据并将
  2. scrollTop到溢出滚动div中的活动元素
  3. [入门篇]Jquery读取.Net WebService Json
  4. html页面传值问题已解决
  5. 关于各种js框架的选择
  6. 使用jquery和ajax更新选项列表
  7. 阻止a标签跳转,且将a的get提交方式转化为p
  8. 将字符串数组发布到.net-core mvc
  9. 使用Rails 3.2和AJAX(非flash上传解决方
  10. 如何在鼠标滚轮上滚动水平滚动?