-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_utilities.ruff
More file actions
94 lines (82 loc) · 2.08 KB
/
Copy pathpath_utilities.ruff
File metadata and controls
94 lines (82 loc) · 2.08 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Path Utilities Demo
// Demonstrates path manipulation functions from stdlib
print("=== Path Utilities Demo ===")
print("")
// Build paths
print("1. Building Paths:")
home_dir := "/home/user"
docs_path := join_path(home_dir, "Documents", "projects", "ruff")
print(" Home directory: " + home_dir)
print(" Documents path: " + docs_path)
config_path := join_path(home_dir, ".config", "ruff", "settings.json")
print(" Config path: " + config_path)
print("")
// Extract path components
print("2. Extracting Path Components:")
full_path := "/home/user/projects/ruff/examples/demo.ruff"
print(" Full path: " + full_path)
print(" Directory: " + dirname(full_path))
print(" Filename: " + basename(full_path))
print("")
// More path examples
paths := [
"/usr/local/bin/ruff",
"src/interpreter.rs",
"README.md",
"/etc/config/settings.json"
]
print("3. Path Analysis:")
for path in paths {
dir := dirname(path)
file := basename(path)
print(" Path: " + path)
print(" Dir: " + dir)
print(" File: " + file)
print("")
}
// Check if paths exist
print("4. Checking Path Existence:")
test_paths := [
"Cargo.toml",
"src",
"README.md",
"nonexistent_file.txt",
"examples"
]
for path in test_paths {
exists := path_exists(path)
status := "✗ Not found"
if exists {
status := "✓ Exists"
}
print(" " + path + ": " + status)
}
print("")
// Build a project structure
print("5. Project Structure Builder:")
project_name := "my_app"
base := join_path("projects", project_name)
dirs := [
base,
join_path(base, "src"),
join_path(base, "tests"),
join_path(base, "docs"),
join_path(base, "examples")
]
files := [
join_path(base, "README.md"),
join_path(base, "Cargo.toml"),
join_path(base, "src", "main.rs"),
join_path(base, "src", "lib.rs"),
join_path(base, "tests", "test_basic.rs")
]
print(" Project: " + project_name)
print(" Directories to create:")
for dir in dirs {
print(" " + dir)
}
print("")
print(" Files to create:")
for file in files {
print(" " + file)
}