Difference between revisions of "API:FS.relativePath"

From Spherical
Jump to: navigation, search
(Add FS.relativePath() page)
 
m
 
Line 1: Line 1:
 
{{DISPLAYTITLE:FS.relativePath()}}
 
{{DISPLAYTITLE:FS.relativePath()}}
  
The '''<tt>FS.relativePath()</tt>''' function computes an abbreviated path for a specified file or directory.
+
The '''<tt>FS.relativePath()</tt>''' [[API:Functions|Core API]] function computes an abbreviated path for a specified file or directory.
  
 
===== Usage =====
 
===== Usage =====

Latest revision as of 18:37, 18 August 2017


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

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

API Information

Description

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);

Parameters

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