How to use glob() to find files recursively?

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

    Johan and Bruno provide excellent solutions on the minimal requirement as stated. I have just released Formic which implements Ant FileSet and Globs which can handle this and more complicated scenarios. An implementation of your requirement is:

    import formic
    fileset = formic.FileSet(include="/src/**/*.c")
    for file_name in fileset.qualified_files():
        print file_name
    

提交回复
热议问题