os.walk without digging into directories below

前端 未结 20 1264
庸人自扰
庸人自扰 2020-12-04 06:21

How do I limit os.walk to only return files in the directory I provide it?

def _dir_list(self, dir_name, whitelist):
    outputList = []
    for         


        
20条回答
  •  执笔经年
    2020-12-04 07:13

    Felt like throwing my 2 pence in.

    baselevel = len(rootdir.split("\\"))
    for subdirs, dirs, files in os.walk(rootdir):
        curlevel = len(subdirs.split("\\"))
        if curlevel <= baselevel + 1:
            [do stuff]
    

提交回复
热议问题