# Path

The **Path** object represents a file or folder path. Many objects have properties that return a **Path** - for example, [**Tab**](tab)**.path** returns the current folder in a tab as a **Path** object. You can create a new **Path** object from a string (or another **Path**) using the [**DOpus**](dopus)**.**[FSUtil](fsutil)**.NewPath** method.

| Property Name      | Return Type                | Description                                                                                                                                                                                                                                                                                                                                                                        |
| ------------------ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| _\<default value>_ | _string_                   | Returns the full path as a string.                                                                                                                                                                                                                                                                                                                                                 |
| components         | _int_                      | Returns the number of components in the path.                                                                                                                                                                                                                                                                                                                                      |
| disks              | [**Vector**](vector)_:int_ | Returns a \*\*[Vector](vector)\*\*of _ints_ representing the physical disk drive or drives that this path resides on.                                                                                                                                                                                                                                                              |
| drive              | _int_                      | Returns the drive number the path refers to (1=A, 2=B, etc.) or 0 if the path does not specify a drive. You can also change the drive letter of the path (while leaving the following path components alone) by modifying this value.                                                                                                                                              |
| ext                | _string_                   | <p>Returns the filename extension of the path (the sub-string extending from the last <strong>.</strong> in the final component to the end of the string). This method does not check if the path actually refers to a file.</p><p>You can also change a path's file extension by setting this property (and strip the extension altogether by setting it to an empty string).</p> |
| ext\_m             | _string_                   | <p>Returns the filename extension of the path, taking multi-part extensions into account. For example, <strong>ext</strong> might return ".rar" whereas <strong>ext_m</strong> would return ".part1.rar".</p><p>You can't change the extension using <strong>ext_m</strong>, only <strong>ext</strong>.</p>                                                                        |
| filepart           | _string_                   | Returns the filename part of the path (the last component).                                                                                                                                                                                                                                                                                                                        |
| longpath           | \*object:\***Path**        | If this object represents a short pathname, this property returns the "long" equivalent.                                                                                                                                                                                                                                                                                           |
| pathpart           | _string_                   | Returns the path minus the last component.                                                                                                                                                                                                                                                                                                                                         |
| shortpath          | \*object:\***Path**        | If this object represents a long pathname, this property returns the "short" equivalent, if it has one. Note that short paths are disabled by default in Windows 10.                                                                                                                                                                                                               |
| stem               | _string_                   | Returns the filename stem of the path (i.e. **filepart** minus **ext**).                                                                                                                                                                                                                                                                                                           |
| stem\_m            | _string_                   | Returns the filename stem taking multi-part extensions into account. For example, **stem** might return "pictures.part1" whereas **stem\_m** would return "pictures".                                                                                                                                                                                                              |
| test\_parent       | _bool_                     | Returns **True** if a call to the **Parent** method would succeed.                                                                                                                                                                                                                                                                                                                 |
| test\_root         | _bool_                     | Returns **True** if a call to the **Root** method would succeed.                                                                                                                                                                                                                                                                                                                   |

| Method Name  | **Arguments**                                                                                                                               | Return Type                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Add          | <p>&#x3C;string:name><br>or &#x3C;<a href="vector"><strong>Vector</strong></a><em>:string></em></p>                                         | _none_                        | Adds the specified name to the path (it will become the last component). As well as a string, you can pass a [**Vector**](vector) of strings and all items in the vector will be added to the path.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Normalize    | _none_                                                                                                                                      | _none_                        | <p>Normalizes the path by:</p><ul><li>Converting all forward-slashes to back-slashes (or vice versa for a URL)</li><li>Collapsing duplicate slashes to a single slash (except where needed)</li></ul><p><strong>Normalize</strong> is automatically called when a new path string is assigned to a <strong>Path</strong> object so you don't normally need to call it manually.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Parent       | _none_                                                                                                                                      | _bool_                        | Removes the last component of the path. Returns **False** if the path does not have a valid parent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ReplaceStart | <p>&#x3C;string:old><br>&#x3C;string:new><br>&#x3C;bool:wholepath></p>                                                                      | _bool_                        | Compares the beginning of the path with the "old" string, and if it matches replaces it with the "new" string. The match is performed at the path component level - for example, an "old" string of "C:\Foo" would match the path "C:\Foo\Bar" but not "C:\FooBar". If the optional _wholepath_ argument is set to **True** then the whole path must match rather than just its beginning. Returns **True** if the string matched the path or **False** otherwise.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Resolve      | \<string:flags>                                                                                                                             | _none_                        | <p>Resolves the specified path string to its real filesystem path, with support for converting:</p><ul><li><a href="../../../basic_concepts/the_lister/navigation/aliases"><strong>Folder Aliases</strong></a> to the real paths they point to.</li><li><strong>Library</strong> and <strong>File Collection</strong> items to their real filesystem paths.</li><li>Application paths in the <strong>{apppath|</strong><em><strong>appname</strong></em><strong>}</strong> form.</li><li>Environment variables.</li><li>Optionally, <strong>junctions</strong> and <strong>symbolic links</strong> can be resolved to their targets. The <strong>Path</strong> object is modified in-place.</li></ul><p>It is safe to pass a path which does not need resolving; the path will remain as-is, so you can call this on things without checking if it is needed first.</p><p>Scripts which pass the current directory to external software should generally call Resolve on the path first, otherwise they risk passing aliases like <em>/desktop</em> to things which won't understand them.</p><p>The optional <strong>flags</strong> string can include the following letter (not case-sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>j</strong></td><td>resolve <strong>j</strong>unctions and symbolic links to their target folder</td></tr></tbody></table><p>Note that <a href="dopus"><strong>DOpus</strong></a><strong>.</strong><a href="fsutil"><strong>FSUtil</strong></a> has a similar <strong>Resolve</strong> method which takes a string input and returns a new <strong>Path</strong> object.</p> |
|              |                                                                                                                                             |                               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| **j**        | resolve **j**unctions and symbolic links to their target folder                                                                             |                               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| Root         | _none_                                                                                                                                      | _bool_                        | Strips off all but the first component of the path. Returns **False** if the path is already at the root.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| Set          | <p>&#x3C;string:path><br>or &#x3C;<strong>Path</strong>:path><br>or &#x3C;<a href="vector"><strong>Vector</strong></a><em>:string></em></p> | _none_                        | <p>Sets the path represented by the <strong>Path</strong> object to the specified <em>string</em>.</p><p>You can also set one <strong>Path</strong> object to the value of another. If you pass a <a href="vector"><strong>Vector</strong></a> of strings the path will be built from the items in the vector.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Split        | <p>&#x3C;int:first><br>&#x3C;int:count></p>                                                                                                 | [**Vector**](vector)_:string_ | Returns a [**Vector**](vector) of strings representing the components of the path. For example, if the path is **C:\Foo\Bar**, the vector will contain three items - "C:\\, "Foo" and "Bar". By default all components of the path are returned, but you can optionally provide the index of the first component and also the number of components to return.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ToUNC        | _none_                                                                                                                                      | _bool_                        | If the path begins with the drive letter of a mapped network drive, it will be converted into the UNC version of the path. For example, "X:\Test" may map to "\Server\Share\Test". Returns **True** if the path was modified and **False** if it was not.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
