-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpath.py
More file actions
30 lines (22 loc) · 688 Bytes
/
path.py
File metadata and controls
30 lines (22 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Python 3.6 or higher
from pathlib import Path
cwd = Path.cwd()
print("Current working directory:\n" + str(cwd))
new_file = Path.joinpath(cwd, "new_file.txt")
print("\nFull path:\n" + str(new_file))
print(new_file.exists())
parent = cwd.parent
print(parent)
print(parent.is_dir())
print(parent.is_file())
# List child directories
print("\n----directory contents------")
for child in parent.iterdir():
if child.is_dir():
print(child)
# file info
demo_file = Path(Path.joinpath(cwd, "demo.txt"))
print("file name: " + demo_file.name)
print("file suffix: " + demo_file.suffix)
print("file folder: " + demo_file.parent.name)
print("file size: " + str(demo_file.stat().st_size))