How to use glob() to find files recursively?

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

    You'll want to use os.walk to collect filenames that match your criteria. For example:

    import os
    cfiles = []
    for root, dirs, files in os.walk('src'):
      for file in files:
        if file.endswith('.c'):
          cfiles.append(os.path.join(root, file))
    

提交回复
热议问题