How to use glob() to find files recursively?

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

    based on other answers this is my current working implementation, which retrieves nested xml files in a root directory:

    files = []
    for root, dirnames, filenames in os.walk(myDir):
        files.extend(glob.glob(root + "/*.xml"))
    

    I'm really having fun with python :)

提交回复
热议问题