How to use the dir/s command in Python?

后端 未结 5 1974
[愿得一人]
[愿得一人] 2021-01-13 07:13

Background

I use the command dir/s in batch files all the time. But, I am unable to call this using python. NOTE: I am

5条回答
  •  不思量自难忘°
    2021-01-13 08:04

    This is a lot different than what you're asking but it solves the same problem. Additionally, it solves it in a pythonic, multiplatform way:

    import fnmatch
    import os
    
    def recglob(directory, ext):
        l = []
        for root, dirnames, filenames in os.walk(directory):
            for filename in fnmatch.filter(filenames, ext):
                l.append(os.path.join(root, filename))
        return l
    

提交回复
热议问题