1## paths.basename 2 3<pre> 4paths.basename(<a href="#paths.basename-p">p</a>) 5</pre> 6 7Returns the basename (i.e., the file portion) of a path. 8 9Note that if `p` ends with a slash, this function returns an empty string. 10This matches the behavior of Python's `os.path.basename`, but differs from 11the Unix `basename` command (which would return the path segment preceding 12the final slash). 13 14 15### Parameters 16 17<table class="params-table"> 18 <colgroup> 19 <col class="col-param" /> 20 <col class="col-description" /> 21 </colgroup> 22 <tbody> 23 <tr id="paths.basename-p"> 24 <td><code>p</code></td> 25 <td> 26 required. 27 <p> 28 The path whose basename should be returned. 29 </p> 30 </td> 31 </tr> 32 </tbody> 33</table> 34 35 36## paths.dirname 37 38<pre> 39paths.dirname(<a href="#paths.dirname-p">p</a>) 40</pre> 41 42Returns the dirname of a path. 43 44The dirname is the portion of `p` up to but not including the file portion 45(i.e., the basename). Any slashes immediately preceding the basename are not 46included, unless omitting them would make the dirname empty. 47 48 49### Parameters 50 51<table class="params-table"> 52 <colgroup> 53 <col class="col-param" /> 54 <col class="col-description" /> 55 </colgroup> 56 <tbody> 57 <tr id="paths.dirname-p"> 58 <td><code>p</code></td> 59 <td> 60 required. 61 <p> 62 The path whose dirname should be returned. 63 </p> 64 </td> 65 </tr> 66 </tbody> 67</table> 68 69 70## paths.is_absolute 71 72<pre> 73paths.is_absolute(<a href="#paths.is_absolute-path">path</a>) 74</pre> 75 76Returns `True` if `path` is an absolute path. 77 78### Parameters 79 80<table class="params-table"> 81 <colgroup> 82 <col class="col-param" /> 83 <col class="col-description" /> 84 </colgroup> 85 <tbody> 86 <tr id="paths.is_absolute-path"> 87 <td><code>path</code></td> 88 <td> 89 required. 90 <p> 91 A path (which is a string). 92 </p> 93 </td> 94 </tr> 95 </tbody> 96</table> 97 98 99## paths.join 100 101<pre> 102paths.join(<a href="#paths.join-path">path</a>, <a href="#paths.join-others">others</a>) 103</pre> 104 105Joins one or more path components intelligently. 106 107This function mimics the behavior of Python's `os.path.join` function on POSIX 108platform. It returns the concatenation of `path` and any members of `others`, 109inserting directory separators before each component except the first. The 110separator is not inserted if the path up until that point is either empty or 111already ends in a separator. 112 113If any component is an absolute path, all previous components are discarded. 114 115 116### Parameters 117 118<table class="params-table"> 119 <colgroup> 120 <col class="col-param" /> 121 <col class="col-description" /> 122 </colgroup> 123 <tbody> 124 <tr id="paths.join-path"> 125 <td><code>path</code></td> 126 <td> 127 required. 128 <p> 129 A path segment. 130 </p> 131 </td> 132 </tr> 133 <tr id="paths.join-others"> 134 <td><code>others</code></td> 135 <td> 136 optional. 137 <p> 138 Additional path segments. 139 </p> 140 </td> 141 </tr> 142 </tbody> 143</table> 144 145 146## paths.normalize 147 148<pre> 149paths.normalize(<a href="#paths.normalize-path">path</a>) 150</pre> 151 152Normalizes a path, eliminating double slashes and other redundant segments. 153 154This function mimics the behavior of Python's `os.path.normpath` function on 155POSIX platforms; specifically: 156 157- If the entire path is empty, "." is returned. 158- All "." segments are removed, unless the path consists solely of a single 159 "." segment. 160- Trailing slashes are removed, unless the path consists solely of slashes. 161- ".." segments are removed as long as there are corresponding segments 162 earlier in the path to remove; otherwise, they are retained as leading ".." 163 segments. 164- Single and double leading slashes are preserved, but three or more leading 165 slashes are collapsed into a single leading slash. 166- Multiple adjacent internal slashes are collapsed into a single slash. 167 168 169### Parameters 170 171<table class="params-table"> 172 <colgroup> 173 <col class="col-param" /> 174 <col class="col-description" /> 175 </colgroup> 176 <tbody> 177 <tr id="paths.normalize-path"> 178 <td><code>path</code></td> 179 <td> 180 required. 181 <p> 182 A path. 183 </p> 184 </td> 185 </tr> 186 </tbody> 187</table> 188 189 190## paths.relativize 191 192<pre> 193paths.relativize(<a href="#paths.relativize-path">path</a>, <a href="#paths.relativize-start">start</a>) 194</pre> 195 196Returns the portion of `path` that is relative to `start`. 197 198Because we do not have access to the underlying file system, this 199implementation differs slightly from Python's `os.path.relpath` in that it 200will fail if `path` is not beneath `start` (rather than use parent segments to 201walk up to the common file system root). 202 203Relativizing paths that start with parent directory references only works if 204the path both start with the same initial parent references. 205 206 207### Parameters 208 209<table class="params-table"> 210 <colgroup> 211 <col class="col-param" /> 212 <col class="col-description" /> 213 </colgroup> 214 <tbody> 215 <tr id="paths.relativize-path"> 216 <td><code>path</code></td> 217 <td> 218 required. 219 <p> 220 The path to relativize. 221 </p> 222 </td> 223 </tr> 224 <tr id="paths.relativize-start"> 225 <td><code>start</code></td> 226 <td> 227 required. 228 <p> 229 The ancestor path against which to relativize. 230 </p> 231 </td> 232 </tr> 233 </tbody> 234</table> 235 236 237## paths.replace_extension 238 239<pre> 240paths.replace_extension(<a href="#paths.replace_extension-p">p</a>, <a href="#paths.replace_extension-new_extension">new_extension</a>) 241</pre> 242 243Replaces the extension of the file at the end of a path. 244 245If the path has no extension, the new extension is added to it. 246 247 248### Parameters 249 250<table class="params-table"> 251 <colgroup> 252 <col class="col-param" /> 253 <col class="col-description" /> 254 </colgroup> 255 <tbody> 256 <tr id="paths.replace_extension-p"> 257 <td><code>p</code></td> 258 <td> 259 required. 260 <p> 261 The path whose extension should be replaced. 262 </p> 263 </td> 264 </tr> 265 <tr id="paths.replace_extension-new_extension"> 266 <td><code>new_extension</code></td> 267 <td> 268 required. 269 <p> 270 The new extension for the file. The new extension should 271 begin with a dot if you want the new filename to have one. 272 </p> 273 </td> 274 </tr> 275 </tbody> 276</table> 277 278 279## paths.split_extension 280 281<pre> 282paths.split_extension(<a href="#paths.split_extension-p">p</a>) 283</pre> 284 285Splits the path `p` into a tuple containing the root and extension. 286 287Leading periods on the basename are ignored, so 288`path.split_extension(".bashrc")` returns `(".bashrc", "")`. 289 290 291### Parameters 292 293<table class="params-table"> 294 <colgroup> 295 <col class="col-param" /> 296 <col class="col-description" /> 297 </colgroup> 298 <tbody> 299 <tr id="paths.split_extension-p"> 300 <td><code>p</code></td> 301 <td> 302 required. 303 <p> 304 The path whose root and extension should be split. 305 </p> 306 </td> 307 </tr> 308 </tbody> 309</table> 310 311 312