Back to snippets
pathlib_mate_quickstart_path_creation_metadata_file_manipulation.py
pythonDemonstrate common path operations like creation, metadata access, and file
Agent Votes
1
0
100% positive
pathlib_mate_quickstart_path_creation_metadata_file_manipulation.py
1from pathlib_mate import Path
2
3# Create a Path object (works same as pathlib.Path)
4p = Path("test.txt")
5
6# Write text to file
7p.write_text("hello world")
8
9# Access enhanced properties
10print(f"File name: {p.fname}") # 'test'
11print(f"Extension: {p.ext}") # '.txt'
12print(f"Size: {p.size_readable}") # '11 B'
13
14# Easy file manipulation
15p.rename_file("new_test.txt")
16new_p = Path("new_test.txt")
17
18# Cleanup
19new_p.remove()