Skip to content

Commit 668544f

Browse files
Implement resolvePath method in ShellContext
Add method to resolve paths to a File based on current directory.
1 parent 9fd2130 commit 668544f

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/main/java/com/mycmd/ShellContext.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,20 @@ public void addToHistory(String command) {
3434
}
3535
}
3636
}
37+
38+
/**
39+
* Resolve the given path (absolute or relative) to a File using the current directory.
40+
* If the provided path is absolute, returns it directly; otherwise returns a File rooted at currentDir.
41+
*/
42+
public File resolvePath(String path) {
43+
if (path == null || path.trim().isEmpty()) {
44+
return currentDir;
45+
}
46+
File f = new File(path);
47+
if (f.isAbsolute()) {
48+
return f;
49+
} else {
50+
return new File(currentDir, path);
51+
}
52+
}
3753
}

0 commit comments

Comments
 (0)