updating oE abbreviate_path


include filesys.e 
namespace filesys 
public function abbreviate_path(sequence orig_path, sequence base_paths = {}) 

returns a path string to the supplied file which is shorter than the given path string.

  1. orig_path : A sequence. This is the path to a file.
  2. base_paths : A sequence. This is an optional list of paths that may prefix the original path. The default is an empty list.

A sequence, an equivalent path to orig_path which is shorter than the supplied path. If a shorter one cannot be formed, then the original path is returned.

  • This function is primarily used to get the shortest form of a file path for output to a file or screen.
  • It works by first trying to find if the orig_path begins with any of the base_paths. If so it returns the parameter minus the base path prefix.
  • Next it checks if the orig_path begins with the current directory path. If so it returns the parameter minus the current directory path.
  • Next it checks if it can form a relative path from the current directory to the supplied file which is shorter than the parameter string.
  • Failing all of that, it returns the original parameter.
  • In Windows the shorter result has all '/' characters are replaced by '\' characters.
  • The supplied path does not have to actually exist.
  • orig_path can be enclosed in quotes, which will be stripped off.
  • If orig_path begins with a tilde '~' then that is replaced by the contents of $HOME in Unix platforms and %HOMEDRIVE%%HOMEPATH% in Windows.
Example 1:
-- Assuming the current directory is "/usr/foo/bar"  
res = abbreviate_path("/usr/foo/abc.def") 
-- res is now "../abc.def" 
res = abbreviate_path("/usr/foo/bar/inc/abc.def") 
-- res is now "inc/abc.def" 
res = abbreviate_path("abc.def", {"/usr/foo"}) 
-- res is now "bar/abc.def" 
Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu