[#BloombergLP-bdls-PathUtil] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdls.adoc[bdls]::PathUtil :relfileprefix: ../../ :mrdocs: This struct contains utility methods for platform‐independent manipulation of filesystem paths. No method of this struct provides any filesystem operations or accesses the filesystem as part of its implementation. == Synopsis Declared in `<bdls_pathutil.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- struct PathUtil; ---- == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdls/PathUtil/appendIfValid-0a.adoc[`appendIfValid`] | Append the specified `filename` to the end of the specified `path` if `filename` represents a relative path. Return 0 on success, and a non‐zero value otherwise. Note that any filesystem separator characters at the end of `filename` or `path` will be discarded. See for the definition of separator. | xref:BloombergLP/bdls/PathUtil/appendRaw-084.adoc[`appendRaw`] | Append the specified `filename` up to the optionally specified `length` to the end of the specified `path`. If `length` is negative, append the entire string. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. The behavior is undefined if `filename` represents an absolute path or if either `filename` or `path` ends with the filesystem separator character. The behavior is also undefined if `filename` points to any part of `path` (i.e., `filename` may not be an alias for `path`). See []and Performance). | xref:BloombergLP/bdls/PathUtil/getBasename-04.adoc[`getBasename`] | Load into the specified `leaf` the value of the rightmost name in the specified `path` that follows the root; that is, the leaf element. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. Return 0 on success, and a non‐zero value otherwise; in particular, return nonzero if `path` does not have a leaf. Note that `getBasename` is a synonym for `getLeaf`. See []and Performance). See also for the definition of leaf and root. | xref:BloombergLP/bdls/PathUtil/getDirname-0b.adoc[`getDirname`] | Load into the specified `dirname` the value of the directory part of the specified `path`, that is, the root if it exists and all the filenames except the last one (the leaf). If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. Return 0 on success, and a non‐zero value otherwise; in particular, return a nonzero value if `path` does not have a leaf. Note that in the case of a relative path with a single filename, the function will succeed and `dirname` will be the empty string. See []and Performance). See also for the definition of directories and root. | xref:BloombergLP/bdls/PathUtil/getExtension-0b.adoc[`getExtension`] | Load into the specified `extension` the extension of `path`. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. Return 0 if the path has an extension, and a non‐zero value otherwise. See []and Performance). See also for the definition of leaf and root. | xref:BloombergLP/bdls/PathUtil/getLeaf-0d.adoc[`getLeaf`] | Load into the specified `leaf` the value of the rightmost name in the specified `path` that follows the root; that is, the leaf element. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. Return 0 on success, and a non‐zero value otherwise; in particular, return nonzero if `path` does not have a leaf. Note that `getBasename` is a synonym for `getLeaf`. See []and Performance). See also for the definition of leaf and root. | xref:BloombergLP/bdls/PathUtil/getRoot-04.adoc[`getRoot`] | Load into the specified 'root' the value of the root part of the specified 'path'. If the optionally specified 'rootEnd' offset is non‐negative, it is taken as the position in 'path' of the character following the root. Return 0 on success, and a non‐zero value otherwise; in particular, return a nonzero value if 'path' is relative. Note that the meaning of the root part is platform‐dependent. See []and Performance). See also for the definition of root. | xref:BloombergLP/bdls/PathUtil/getRootEnd.adoc[`getRootEnd`] | Return the 0‐based position in the specified `path` of the character following the root. Note that a return value of 0 indicates a relative path. See []and Performance). See also for the definition of root. | xref:BloombergLP/bdls/PathUtil/hasLeaf.adoc[`hasLeaf`] | Return `true` if the specified `path` has a filename following the root, and `false` otherwise. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. See []and Performance). See also for the definition of root. | xref:BloombergLP/bdls/PathUtil/isAbsolute.adoc[`isAbsolute`] | Return `true` if the specified `path` is absolute (has a root), and `false` otherwise. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. See []and Performance). See also for the definition of root. | xref:BloombergLP/bdls/PathUtil/isRelative.adoc[`isRelative`] | Return `true` if the specified `path` is relative (lacks a root), and `false` otherwise. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. See []and Performance). See also for the definition of root. | xref:BloombergLP/bdls/PathUtil/popLeaf-0f.adoc[`popLeaf`] | Remove from the specified `path` the rightmost filename following the root; that is, remove the leaf element. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. Return 0 on success, and a nonzero value otherwise; in particular, return a nonzero value if `path` does not have a leaf. See []and Performance). See also for the definition of leaf and root. | xref:BloombergLP/bdls/PathUtil/splitFilename.adoc[`splitFilename`] | Load the last pathname component from the specified `path` into the specified `tail` and everything leading up to that to the specified `head`. If the optionally specified `rootEnd` offset is non‐negative, it is taken as the position in `path` of the character following the root. The `tail` part never contains a slash; if `path` ends in a slash, `tail` is empty. If there is no slash in `path`, `head` is empty. If `path` is empty, both `head` and `tail` are empty. Trailing slashes are stripped from `head` unless it is the root. ` +‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+ | PATH | HEAD | TAIL | +#++#===+ | "one" | "" | "one" | +‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+ | "/one/two/three" | "/one/two" | "three" | +‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+ | "//one/two///" | "/one/two" | "" | +‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+ | "c:\one\two" | "c:\one" | "two" | +‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+ ` See {`Terminology`} for the definition of root. The behavior is undefined unless `head != tail` and `INT_MAX >= path.length()`. Note that `head` or `tail` may point to the `path` object when the method is called. |=== == Static Data Members [cols="1"] |=== | Name | xref:BloombergLP/bdls/PathUtil/k_SEPARATOR.adoc[`k_SEPARATOR`] |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#