Listing 09-13: Directory tree being visited through

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 09\09.13 - Directory tree being visited through - with pathlib.py
# Description: Directory tree being visited through - with pathlib
##############################################################################

import sys
from pathlib import Path

for root, directories, files in Path(sys.argv[1]).walk():
    print("\nPath:", root)
    for d in directories:
        print(f"  {d}/")
    for f in files:
        print(f"  {f}")
    print(f"{len(directories)} directory(s), {len(files)} file(s)")
Click here to download the file