How to use glob() to find files recursively?

前端 未结 28 2342
天涯浪人
天涯浪人 2020-11-21 22:54

This is what I have:

glob(os.path.join(\'src\',\'*.c\'))

but I want to search the subfolders of src. Something like this would work:

<
28条回答
  •  广开言路
    2020-11-21 23:23

    Or with a list comprehension:

     >>> base = r"c:\User\xtofl"
     >>> binfiles = [ os.path.join(base,f) 
                for base, _, files in os.walk(root) 
                for f in files if f.endswith(".jpg") ] 
    

提交回复
热议问题