How do I read the number of files in a folder using Python?

后端 未结 6 1987
醉酒成梦
醉酒成梦 2021-02-07 11:56

How do I read the number of files in a specific folder using Python? Example code would be awesome!

6条回答
  •  臣服心动
    2021-02-07 12:38

    recursive solution:

    sum(len(fs) for _,_,fs in os.walk(os.getcwd()))
    

    for current directory solution:

    len(os.walk(os.getcwd()).next()[2])
    

提交回复
热议问题