-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpathlib_types.py
More file actions
39 lines (33 loc) · 892 Bytes
/
pathlib_types.py
File metadata and controls
39 lines (33 loc) · 892 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
31
32
33
34
35
36
37
38
39
import itertools
import os
import pathlib
root = pathlib.Path("test_files")
# Clean up from previous runs.
if root.exists():
for f in root.iterdir():
f.unlink()
else:
root.mkdir()
# Create test files
(root / "file").write_text("This is a regular file", encoding="utf-8")
(root / "symlink").symlink_to("file")
os.mkfifo(str(root / "fifo"))
# Check the file types
to_scan = itertools.chain(
root.iterdir(), [pathlib.Path("/dev/disk0"), pathlib.Path("/dev/console")]
)
hfmt = "{:18s}" + (" {:>5}" * 6)
print(hfmt.format("Name", "File", "Dir", "Link", "FIFO", "Block", "Character"))
fmt = "{:20s} " + ("{!r:>5} " * 6)
for f in to_scan:
print(
fmt.format(
str(f),
f.is_file(),
f.is_dir(),
f.is_symlink(),
f.is_fifo(),
f.is_block_device(),
f.is_char_device(),
)
)