workshopper-browser-guide
Version:
Create an html browser version of the exercise descriptions
316 lines (271 loc) • 12.2 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>Path Node.js v0.10.35 Manual & Documentation</title>
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/sh.css">
<link rel="canonical" href="http://nodejs.org/api/path.html">
<script type="text/javascript" src="//use.typekit.net/mse5tqx.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
</head>
<body class="alt apidoc int docs" id="docs">
<div id="nav">
<img id="logo" src="assets/logo.svg" alt="node.js">
<ul>
<li><a href="http://nodejs.org">Home</a></li>
<li><a href="http://nodejs.org/download/">Downloads</a></li>
<li class="active"><a href="http://nodejs.org/documentation/">Docs</a></li>
<li><a href="http://nodejs.org/community/">Community</a></li>
<li><a href="http://nodejs.org/about/">About</a></li>
<li><a href="http://jobs.nodejs.org">Jobs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
</ul>
</div>
<div id="content-wrap">
<div id="content" class="clearfix">
<div id="column2" class="interior">
<!--<img src="/images/logo-light.svg" alt="node.js" width="170">-->
<ul class="docs-nav">
<li><a href="http://nodejs.org/documentation/">About Docs</a></li>
<li><a href="http://nodejs.org/documentation/tutorials/">Tutorials</a></li>
<li><a href="http://nodejs.org/documentation/contributing/">Contributing</a></li>
<li><a href="http://nodejs.org/documentation/localization/">Localization</a></li>
<li class="active"><a href="http://nodejs.org/api/">API Docs</a></li>
</ul>
</div>
<div id="column1" class="interior">
<header>
<h1>Node.js v0.10.35 Manual & Documentation</h1>
<div id="gtoc">
<p>
<a href="index.html" name="toc">Index</a> |
<a href="all.html">View on single page</a> |
<a href="path.json">View as JSON</a>
</p>
</div>
<hr>
</header>
<div id="toc">
<h2>Table of Contents</h2>
<ul>
<li><a href="#path_path">Path</a><ul>
<li><a href="#path_path_normalize_p">path.normalize(p)</a></li>
<li><a href="#path_path_join_path1_path2">path.join([path1], [path2], [...])</a></li>
<li><a href="#path_path_resolve_from_to">path.resolve([from ...], to)</a></li>
<li><a href="#path_path_relative_from_to">path.relative(from, to)</a></li>
<li><a href="#path_path_dirname_p">path.dirname(p)</a></li>
<li><a href="#path_path_basename_p_ext">path.basename(p, [ext])</a></li>
<li><a href="#path_path_extname_p">path.extname(p)</a></li>
<li><a href="#path_path_sep">path.sep</a></li>
<li><a href="#path_path_delimiter">path.delimiter</a></li>
</ul>
</li>
</ul>
</div>
<div id="apicontent">
<h1>Path<span><a class="mark" href="#path_path" id="path_path">#</a></span></h1>
<pre class="api_stability_3">Stability: 3 - Stable</pre><p>This module contains utilities for handling and transforming file
paths. Almost all these methods perform only string transformations.
The file system is not consulted to check whether paths are valid.
</p>
<p>Use <code>require('path')</code> to use this module. The following methods are provided:
</p>
<h2>path.normalize(p)<span><a class="mark" href="#path_path_normalize_p" id="path_path_normalize_p">#</a></span></h2>
<p>Normalize a string path, taking care of <code>'..'</code> and <code>'.'</code> parts.
</p>
<p>When multiple slashes are found, they're replaced by a single one;
when the path contains a trailing slash, it is preserved.
On Windows backslashes are used.
</p>
<p>Example:
</p>
<pre><code>path.normalize('/foo/bar//baz/asdf/quux/..')
// returns
'/foo/bar/baz/asdf'</code></pre>
<h2>path.join([path1], [path2], [...])<span><a class="mark" href="#path_path_join_path1_path2" id="path_path_join_path1_path2">#</a></span></h2>
<p>Join all arguments together and normalize the resulting path.
</p>
<p>Arguments must be strings. In v0.8, non-string arguments were
silently ignored. In v0.10 and up, an exception is thrown.
</p>
<p>Example:
</p>
<pre><code>path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
// returns
'/foo/bar/baz/asdf'
path.join('foo', {}, 'bar')
// throws exception
TypeError: Arguments to path.join must be strings</code></pre>
<h2>path.resolve([from ...], to)<span><a class="mark" href="#path_path_resolve_from_to" id="path_path_resolve_from_to">#</a></span></h2>
<p>Resolves <code>to</code> to an absolute path.
</p>
<p>If <code>to</code> isn't already absolute <code>from</code> arguments are prepended in right to left
order, until an absolute path is found. If after using all <code>from</code> paths still
no absolute path is found, the current working directory is used as well. The
resulting path is normalized, and trailing slashes are removed unless the path
gets resolved to the root directory. Non-string <code>from</code> arguments are ignored.
</p>
<p>Another way to think of it is as a sequence of <code>cd</code> commands in a shell.
</p>
<pre><code>path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')</code></pre>
<p>Is similar to:
</p>
<pre><code>cd foo/bar
cd /tmp/file/
cd ..
cd a/../subfile
pwd</code></pre>
<p>The difference is that the different paths don't need to exist and may also be
files.
</p>
<p>Examples:
</p>
<pre><code>path.resolve('/foo/bar', './baz')
// returns
'/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/')
// returns
'/tmp/file'
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// if currently in /home/myself/node, it returns
'/home/myself/node/wwwroot/static_files/gif/image.gif'</code></pre>
<h2>path.relative(from, to)<span><a class="mark" href="#path_path_relative_from_to" id="path_path_relative_from_to">#</a></span></h2>
<p>Solve the relative path from <code>from</code> to <code>to</code>.
</p>
<p>At times we have two absolute paths, and we need to derive the relative
path from one to the other. This is actually the reverse transform of
<code>path.resolve</code>, which means we see that:
</p>
<pre><code>path.resolve(from, path.relative(from, to)) == path.resolve(to)</code></pre>
<p>Examples:
</p>
<pre><code>path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb')
// returns
'..\\..\\impl\\bbb'
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')
// returns
'../../impl/bbb'</code></pre>
<h2>path.dirname(p)<span><a class="mark" href="#path_path_dirname_p" id="path_path_dirname_p">#</a></span></h2>
<p>Return the directory name of a path. Similar to the Unix <code>dirname</code> command.
</p>
<p>Example:
</p>
<pre><code>path.dirname('/foo/bar/baz/asdf/quux')
// returns
'/foo/bar/baz/asdf'</code></pre>
<h2>path.basename(p, [ext])<span><a class="mark" href="#path_path_basename_p_ext" id="path_path_basename_p_ext">#</a></span></h2>
<p>Return the last portion of a path. Similar to the Unix <code>basename</code> command.
</p>
<p>Example:
</p>
<pre><code>path.basename('/foo/bar/baz/asdf/quux.html')
// returns
'quux.html'
path.basename('/foo/bar/baz/asdf/quux.html', '.html')
// returns
'quux'</code></pre>
<h2>path.extname(p)<span><a class="mark" href="#path_path_extname_p" id="path_path_extname_p">#</a></span></h2>
<p>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:
</p>
<pre><code>path.extname('index.html')
// returns
'.html'
path.extname('index.coffee.md')
// returns
'.md'
path.extname('index.')
// returns
'.'
path.extname('index')
// returns
''</code></pre>
<h2>path.sep<span><a class="mark" href="#path_path_sep" id="path_path_sep">#</a></span></h2>
<p>The platform-specific file separator. <code>'\\'</code> or <code>'/'</code>.
</p>
<p>An example on *nix:
</p>
<pre><code>'foo/bar/baz'.split(path.sep)
// returns
['foo', 'bar', 'baz']</code></pre>
<p>An example on Windows:
</p>
<pre><code>'foo\\bar\\baz'.split(path.sep)
// returns
['foo', 'bar', 'baz']</code></pre>
<h2>path.delimiter<span><a class="mark" href="#path_path_delimiter" id="path_path_delimiter">#</a></span></h2>
<p>The platform-specific path delimiter, <code>;</code> or <code>':'</code>.
</p>
<p>An example on *nix:
</p>
<pre><code>console.log(process.env.PATH)
// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
process.env.PATH.split(path.delimiter)
// returns
['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']</code></pre>
<p>An example on Windows:
</p>
<pre><code>console.log(process.env.PATH)
// 'C:\Windows\system32;C:\Windows;C:\Program Files\nodejs\'
process.env.PATH.split(path.delimiter)
// returns
['C:\Windows\system32', 'C:\Windows', 'C:\Program Files\nodejs\']</code></pre>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="foot-1">
<a href="http://www.joyent.com"><h5>The Node.js Project is Sponsored by</h5>
<img src="assets/joyent-footer.svg" width="200">
<p class="tag">Production Node +<br>High Performance Infrastructure</p></a>
<a href="https://my.joyent.com/landing/signup/701800000015696" class="button getstarted">Get Started</a>
</div>
<div class="foot-2">
<div class="foot-nav">
<ul>
<li><a href="http://nodejs.org/download/">Downloads</a></li>
</ul>
<ul>
<li><a href="http://nodejs.org/documentation/">Documentation</a></li>
<li><a href="http://nodejs.org/api/">API Docs</a></li>
<li><a href="http://nodejs.org/documentation/tutorials/">Tutorials</a></li>
<li><a href="http://nodejs.org/documentation/localization/">Localization</a></li>
</ul>
<ul>
<li><a href="http://nodejs.org/community/">Community</a></li>
<li><a href="https://github.com/joyent/node/issues">Github Issues</a></li>
<li><a href="http://groups.google.com/group/nodejs">Mailing List</a></li>
<li><a href="http://webchat.freenode.net/?channels=node.js">IRC</a></li>
<li><a href="https://twitter.com/nodejs">Twitter</a></li>
</ul>
<ul>
<li><a href="http://nodejs.org/about/">About</a></li>
<li><a href="http://nodejs.org/about/organization/">Organization</a></li>
<li><a href="http://nodejs.org/about/core-team/">Core Team</a></li>
<li><a href="http://nodejs.org/about/resources/">Resources</a></li>
</ul>
<ul>
<li><a href="http://blog.nodejs.org">Blog</a></li>
</ul>
</div>
<p class="copyright">Copyright 2014 <a href="http://joyent.com/">Joyent, Inc</a>, Node.js is a <a href="https://nodejs.org/images/trademark-policy.pdf">trademark</a> of Joyent, Inc. <a href="https://raw.github.com/joyent/node/v0.10.35/LICENSE">View license</a>.</p>
</div>
</div>
<script src="/sh_main.js"></script>
<script src="/sh_javascript.min.js"></script>
<script>highlight(undefined, undefined, 'pre');</script>
<script>
window._gaq = [['_setAccount', 'UA-10874194-2'], ['_trackPageview']];
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = '//www.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));
</script>
</body>
</html>