## DuPath

Paths related methods

View Source DuAEF_Duik_api.jsxinc, line 510

# Members

Type: `string`

#### # static readonly SizeUnit

Units to use for sizes.

##### Properties:

Name | Type | Description
--- | --- | ---
`BIT` | `string` |
`BYTE` | `string` |
`KB` | `string` |
`MB` | `string` |
`GB` | `string` |
`TB` | `string` |

View Source DuAEF_Duik_api.jsxinc, line 517

# Methods

#### # static fixName(name, placeholderopt) → {string}

Removes all forbidden characters from a string to be used as a filename

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`name` | `string` |  |  | The filename to fix
`placeholder` | `string` | <optional> | '.' | The string used to replace the forbidden characters

View Source DuAEF_Duik_api.jsxinc, line 699

Returns:
The fixed filename
Type: `string`

#### # static getBasename(pathOrFileopt) → {String}

Returns the basename of the given path or file

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`pathOrFile` | `String` | `File` | <optional> | The file or the path

View Source DuAEF_Duik_api.jsxinc, line 602

Returns:
The basename
Type: `String`

##### Example

    DuPath.getBasename(new File("D:/code/open/Duik/shape.test")) // "shape"
    DuPath.getBasename("D:/code/open/Duik/shape.test") // "shape"

#### # static getExtension(pathOrFileopt) → {String}

Returns the extension of the given path or file

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`pathOrFile` | `String` | `File` | <optional> | The file or the path

View Source DuAEF_Duik_api.jsxinc, line 623

Returns:
The extension
Type: `String`

##### Example

    DuPath.getExtension(new File("D:/code/open/Duik/shape.other.test")) // "test"
    DuPath.getExtension("D:/code/open/Duik/shape.test") // "test"

#### # static getName(pathOrFileopt) → {String}

Returns the name of the given path or file, as displayed by the filesystem

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`pathOrFile` | `String` | `File` | `Folder` | <optional> | The file or the path

View Source DuAEF_Duik_api.jsxinc, line 582

Returns:
The basename
Type: `String`

##### Example

    DuPath.getName(new File("D:\\code\\open\\Duik\\shape test.test")) // "shape test.test"
    DuPath.getName("D:/code/open/Duik/other shape.test") // "other shape.test"

#### # static incrementName(file) → {string}

Increments the last number before the extension in a filename

##### Parameters:

Name | Type | Description
--- | --- | ---
`file` | `File` | The file

View Source DuAEF_Duik_api.jsxinc, line 670

Returns:
The incremented fileName
Type: `string`

#### # static isFile(path) → {bool}

Checks if the given path represents an existing file

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | `File` | `Folder` | `string` | The path to check

View Source DuAEF_Duik_api.jsxinc, line 710

Returns:
Type: `bool`

#### # static isFolder(path) → {bool}

Checks if the given path represents an existing folder

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | `File` | `Folder` | `string` | The path to check

View Source DuAEF_Duik_api.jsxinc, line 726

Returns:
Type: `bool`

#### # static join(partsopt, sepopt) → {String}

Joins multiple paths togetther.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`parts` | `Array.<string>` | <optional> |  | The parts to join togehter
`sep` | `String` | <optional> | "/" | The separator to use. If not defined, will look for the first sep in the path.

View Source DuAEF_Duik_api.jsxinc, line 532

Returns:
The final path
Type: `String`

#### # static newUniqueName(newName, folder, incrementopt) → {string}

Generates a new unique name for a file

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`newName` | `string` |  |  | The wanted new name
`folder` | `Folder` |  |  | The folder
`increment` | `boolean` | <optional> | true | true to automatically increment the new name if it already ends with a digit

View Source DuAEF_Duik_api.jsxinc, line 656

Returns:
The unique name, with a new number at the end if needed.
Type: `string`

#### # static sizeFromBytes(size, toopt, decimalsopt) → {float}

Converts a number of Bytes to kB or MB or GB or TB For conversion to bits, a Byte is considered to be 8 bits.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`size` | `int` |  |  | The size in Bytes to convert
`to` | `DuPath.SizeUnit` | <optional> | DuPath.SizeUnit.MB | The unit to convert to, one of: b, kB, MB, GB, TB
`decimals` | `int` | <optional> | 2 | The number of decimals to round the result

View Source DuAEF_Duik_api.jsxinc, line 554

Returns:
The result of the conversion
Type: `float`

#### # static switchExtension(pathOrFileopt, newExtensionopt) → {String}

Switch the extension of the given path. Create a new path from a given path and a given extension.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`pathOrFile` | `String` | `File` | <optional> | The file or the path
`newExtension` | `String` | <optional> | The new extension

View Source DuAEF_Duik_api.jsxinc, line 639

Returns:
The new path
Type: `String`