Skip to content

pathlib

jasper-zanjani edited this page Aug 6, 2020 · 1 revision

Create a new pathlib object; represents a file or directory

pathlib.Path(path)

Test for existence of a file

pathlib.Path.is_file(file)

Test for existence of a directory

pathlib.Path.is_dir(dir)

Find all .py files Returns a generator

pathlib.Path.glob('*.py')

Open a file. This makes a file object that is automatically closed, similar to open builtin:

pathlib.Path.open()

Display file extension

pathlib.Path.suffix()

Display file size

pathlib.Path.stat().st_size

Clone this wiki locally