Git Product home page Git Product logo

path's Introduction

SYNOPSIS

Utilities for handling and transforming filesystem paths.

USAGE

This module is designed to work with the datcxx build tool. To add this module to your project us the following command...

build add datcxx/path

TEST

build test

API

string Path::join(string path1, string path2[, ...]);

Join all arguments together and normalize the resulting path. Arguments must be strings.

Path::join("/foo", "bar", "baz/asdf", "quux", "..");
// returns "/foo/bar/baz/asdf"

bool Path::isAbsolute(string path);

Determines whether path is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.

Path::isAbsolute("/foo/bar"); // true
Path::isAbsolute("/baz/.."); // true
Path::isAbsolute("qux/"); // false
Path::isAbsolute("."); // false

string Path::dirname(string path);

Return the directory name of a path. Similar to the Unix dirname command.

Path::dirname("/foo/bar/baz/asdf/quux");
// returns "/foo/bar/baz/asdf"

string Path::basename(string path[, string ext]);

Return the last portion of a path. Similar to the Unix basename command.

Path::basename("/foo/bar/baz/asdf/quux.html");
// returns "quux.html"

Path::basename("/foo/bar/baz/asdf/quux.html", ".html");
// returns "quux"

string path.extname(string path);

Return the extension of the path, from the last "." to end of string in the last portion of the path. If there is no "." in the last portion of the path or the first character of it is ".", then it returns an empty string. Examples:

Path::extname("index.html");
// returns ".html"

Path::extname("index.coffee.md");
// returns ".md"

Path::extname("index.");
// returns "."

Path::extname("index");
// returns ""

string path.relative(string from, string to);

Return the relative path between from and to according to the current working directory. If from and to resolve to the same path (using path.resolve) an empty string is returned.

If either of the provided from or to parameters, the current working directory will be used in their place.

Examples:

Path::relative("/var/lib", "/var");
// returns ".."

Path::relative("/var/lib", "/bin");
// return "../../bin"

Path::relative("/foo/test", "/foo/test/bar/package.json");

// returns "bar/package.json"

Path::relative("/Users/a/web/b/test/mails", "/Users/a/web/b");

// returns "../.."

string Path::parse(string path);

Returns an object from a path string.

auto o = Path::parse("/home/user/dir/file.txt");

Returns a struct of type PathObject with the following members...

o.root = "/";
o.dir = "/home/user/dir";
o.base = "file.txt";
o.ext = ".txt";
o.name = "file";

PathObject Path::format(struct pathObject);

Returns a path string from an object, the opposite of path.parse above. The struct can be created with the path.createObject() method.

auto o = Path::createObject();

o.dir = "/home/user/dir";
o.base = "file.txt";
o.ext = ".txt";
o.name = "file";

Path::format(o);
// returns "/home/user/dir/file.txt"

string Path::resolve(string path);

Resolves to to an absolute path. If to isn"t already absolute from arguments are prepended in right to left order, until an absolute path is found. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory. Non-string from arguments will throw an error.

Another way to think of it is as a sequence of cd commands in a shell.

Path::resolve("/foo/bar", "./baz");
// returns "/foo/bar/baz"

Path::resolve("/foo/bar", "/tmp/file/");
// returns "/tmp/file"

path's People

Contributors

heapwolf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.