# Path

The **Path** object represents a file or folder path. Many objects have properties that return a **Path** - for example, [**Tab**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/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**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/dopus)**.**[FSUtil](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/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**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/vector)*:int* | Returns a \*\*[Vector](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/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>\<string:name><br>or <<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**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/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>\<string:old><br>\<string:new><br>\<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><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>\<string:path><br>or <<strong>Path</strong>:path><br>or <<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>\<int:first><br>\<int:count></p>                                                                                           | [**Vector**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/vector)*:string* | Returns a [**Vector**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/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.                                                                                                                                                                                                          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
