base/utils/paths.bro

Functions to parse and manipulate UNIX style paths and directories.

Source File:/scripts/base/utils/paths.bro

Summary

Functions

build_path: function Constructs a path to a file given a directory and a file name.
build_path_compressed: function Returns a compressed path to a file given a directory and file name.
compress_path: function Compresses a given path by removing ‘..’s and the parent directory it references and also removing dual ‘/’s and extraneous ‘/./’s.
extract_path: function Given an arbitrary string, extracts a single, absolute path (directory with filename).

Detailed Interface

Constants

absolute_path_pat
Type:pattern
Default:
/^?((\/|[A-Za-z]:[\\\/]).*)$?/

Functions

build_path
Type:function (dir: string, file_name: string) : string

Constructs a path to a file given a directory and a file name.

Dir:the directory in which the file lives.
File_name:the name of the file.
Returns:the concatenation of the directory path and file name, or just the file name if it’s already an absolute path.
build_path_compressed
Type:function (dir: string, file_name: string) : string

Returns a compressed path to a file given a directory and file name. See build_path and compress_path.

compress_path
Type:function (dir: string) : string

Compresses a given path by removing ‘..’s and the parent directory it references and also removing dual ‘/’s and extraneous ‘/./’s.

Dir:a path string, either relative or absolute.
Returns:a compressed version of the input path.
extract_path
Type:function (input: string) : string

Given an arbitrary string, extracts a single, absolute path (directory with filename).

Todo

Make this work on Window’s style directories.

Input:a string that may contain an absolute path.
Returns:the first absolute path found in input string, else an empty string.
Copyright 2016, The Bro Project. Last updated on January 10, 2019. Created using Sphinx 1.7.5.