filepath
Path functions that never touch the file system; the same work as the fs/path package.
import filepath
The filepath package works on strings alone and never touches the file system, apart from Abs, which needs the current directory. The fs.path package is built on it; use whichever reads better to you.
Constants and variables
Separator
const Separator: str = "/"/.import filepath
func main:
p := filepath.Join("projects", "salam/main.salam")
println p, filepath.Separator
println filepath.Dir(p), filepath.Base(p), filepath.Ext(p), filepath.Stem(p)
println filepath.Normalize("a//b/./c/"), filepath.Clean("a/b/../c")
println filepath.IsAbs("/usr/bin"), filepath.IsAbs(p), filepath.IsAbs(filepath.Abs(p))
println filepath.Rel("/a/b", "/a/b/c/d")
println filepath.IsSafe("/srv", "x/y"), filepath.IsSafe("/srv", "../etc")
println filepath.Validate("a/b")
endFunctions
Normalize
func Normalize(p: str): str\ separators into /.The example for this item is shown with the ones above: filepath-Join.salam
IsAbs
func IsAbs(p: str): boolC:/ counts as absolute.The example for this item is shown with the ones above: filepath-Join.salam
Join
func Join(a: str, b: str): strThe example for this item is shown with the ones above: filepath-Join.salam
Base
func Base(p: str): strThe example for this item is shown with the ones above: filepath-Join.salam
Dir
func Dir(p: str): strThe example for this item is shown with the ones above: filepath-Join.salam
Ext
func Ext(p: str): strThe example for this item is shown with the ones above: filepath-Join.salam
Stem
func Stem(p: str): strThe example for this item is shown with the ones above: filepath-Join.salam
Clean
func Clean(p: str): strThe example for this item is shown with the ones above: filepath-Join.salam
Abs
func Abs(p: str): strThe example for this item is shown with the ones above: filepath-Join.salam
Rel
func Rel(base: str, target: str): strbase to target.The example for this item is shown with the ones above: filepath-Join.salam
Validate
func Validate(p: str): boolThe example for this item is shown with the ones above: filepath-Join.salam
IsSafe
func IsSafe(base: str, p: str): boolbase.The example for this item is shown with the ones above: filepath-Join.salam