Skip to content

Using Paths

Thibaut Lamadon edited this page Jun 8, 2022 · 2 revisions

Just a few notes on using pathlib. You can pass pathlib objects to input and output fields of Tasks.

from pathlib import Path

# define a path
path = Path('mynewfolder')

# make sure the path exists
path.mkdir(parents=True, exist_ok=True)

# refer to a file on that path
my_file = path / Path('somefile.txt')

# check if file exists
my_file.exists()

# get a list of files with glob
list(path.glob('*.txt'))

# replace filename or file extension
path.with_name('bye')
path.with_suffix('.tex')
Clone this wiki locally