Return number of files in directory and subdirectory

前端 未结 3 1866
抹茶落季
抹茶落季 2020-12-30 19:25

Trying to create a function that returns the # of files found a directory and its subdirectories. Just need help getting started

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 19:48

    Use os.walk. It will do the recursion for you. See http://www.pythonforbeginners.com/code-snippets-source-code/python-os-walk/ for an example.

    total = 0
    for root, dirs, files in os.walk(folder):
        total += len(files)
    

提交回复
热议问题