From Spherical
Revision as of 18:37, 18 August 2017 by Bruce Pascoe (talk | contribs)
Jump to: navigation, search

The FS.relativePath() Core API function computes an abbreviated path for a specified file or directory.

rel_path = FS.relativePath(file_or_dir_name[, base_dir_name]);

API Information


FS.relativePath() takes a file or directory name and returns an abbreviated version relative to a specified base directory. This is useful when logging or displaying filenames where the full path might be too verbose.

If the SphereFS prefixes of the (canonicalized) input path and base directory differ, then the full pathname is returned without attempting to abbreviate it. This ensures that one can always recover the original path by doing:

rel_path = FS.relativePath(path, base_dir);
/* ... */
path = FS.fullPath(rel_path, base_dir);


Name Type Default Description
file_or_dir_name string The name of a file or directory, resolved per SphereFS rules (relative to @/). It doesn't need to actually exist.
base_dir_name string Specifies the base directory for the relative path.

Return Value

An abbreviated version of file_or_dir_name relative to the specified base directory.

See Also