Check if the path starts with the dir path.
is_sub_path(x, dir, n = nchar(dir))
A logical vector.
You may want to normalize the values of the x
and dir
arguments
first (with normalize_path()
), to make sure the path separators
are consistent.
xfun::is_sub_path("a/b/c.txt", "a/b") # TRUE
#> [1] TRUE
xfun::is_sub_path("a/b/c.txt", "d/b") # FALSE
#> [1] FALSE
xfun::is_sub_path("a/b/c.txt", "a\\b") # FALSE (even on Windows)
#> [1] FALSE