python
from pathlib import Path
python
file_path = Path("path/to/file.txt")
python
dir_path = Path("path/to/directory")
python
exists = dir_path.exists()
python
is_file = file_path.is_file()
is_dir = dir_path.is_dir()
python
file_name = file_path.name
file_extension = file_path.suffix
python
parent_dir = file_path.parent
python
absolute_path = file_path.absolute()
python
new_path = dir_path / "subdir" / file_path
python
files = dir_path.glob('*.txt')
for file in files:
print(file)
python
dir_path.mkdir()
python
file_path.touch()
python
dir_path.copy_to("new_directory")
file_path.copy_to("new_file.txt")