How to use glob() to find files recursively?

前端 未结 28 2175
天涯浪人
天涯浪人 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:31

    I've modified the glob module to support ** for recursive globbing, e.g:

    >>> import glob2
    >>> all_header_files = glob2.glob('src/**/*.c')
    

    https://github.com/miracle2k/python-glob2/

    Useful when you want to provide your users with the ability to use the ** syntax, and thus os.walk() alone is not good enough.

提交回复
热议问题