from pathlib import Path path = Path('/home/user/filename.txt') print(path.name)
from pathlib import Path path = Path('.') for p in path.iterdir(): print(p)In this example, we create a Path object named `path` for the current directory (`.`). We then use the `iterdir()` method of the Path object to iterate over all the files and directories in the current directory, and print them out. The package library for Python pathlib Path is 'pathlib'.