## DuFile

File related methods

View Source Duik_api_fordoc.jsxinc, line 6937

# Members

Type: `Array.<string>`

#### # static base64Chars

The list of legit characters for base64 encoding

View Source Duik_api_fordoc.jsxinc, line 6943

# Methods

#### # static checkBase64(b64) → {bool}

Checks if the base64 string seems valid

##### Parameters:

Name | Type | Description
--- | --- | ---
`b64` | `string` | The string to check

View Source Duik_api_fordoc.jsxinc, line 7218

Returns:
Type: `bool`

#### # static exists(pathopt) → {boolean}

Checks if the given path exists

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`path` | `string` | <optional> | The file path

View Source Duik_api_fordoc.jsxinc, line 7015

Returns:
True or false
Type: `boolean`

#### # static fromBase64(b64, file) → {File|null}

Writes a file from a base64 string.

##### Parameters:

Name | Type | Description
--- | --- | ---
`b64` | `string` | The base64 string
`file` | `string` | `File` | The destination file or its path

View Source Duik_api_fordoc.jsxinc, line 7239

Returns:
The File object or null if it fails
Type: `File` | `null`

#### # static getSequenceNumber(path)

Gets the number of a frame from an file/image sequence
The number must be right before the extension.

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | `string` | The path of the frame

View Source Duik_api_fordoc.jsxinc, line 7290

#### # static move(file, newURI) → {File|null}

Moves a file to a new location

##### Parameters:

Name | Type | Description
--- | --- | ---
`file` | `string` | `File` | The file
`newURI` | `string` | `File` | The new URI/Path (including file name)

View Source Duik_api_fordoc.jsxinc, line 7313

Returns:
the new file object, or null if it could not be moved
Type: `File` | `null`

#### # static parseCSV(file, delimiteropt, textSeparatoropt) → {Array.<string>|null}

Parses a CSV file

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`file` | `File` |  |  | The file
`delimiter` | `string` | <optional> | ',' | The delimiter used
`textSeparator` | `string` | <optional> | '"' | The separator for texts

View Source Duik_api_fordoc.jsxinc, line 7159

Returns:
The content (a two-dimensionnal Array) or null if the file couldn't be parsed
Type: `Array.<string>` | `null`

#### # static parseJSON(file) → {Object|null}

Parses a JSON file

##### Parameters:

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

View Source Duik_api_fordoc.jsxinc, line 7126

Returns:
The content or null if the file couldn't be parsed
Type: `Object` | `null`

#### # static read(file, encodingopt) → {string}

Reads a whole file and return its content

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`file` | `File` | `string` |  |  | The file
`encoding` | `string` | <optional> | 'UTF-8' | The text encoding

View Source Duik_api_fordoc.jsxinc, line 7044

Returns:
The content
Type: `string`

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

Reads the first line of a file and return its content

##### Parameters:

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

View Source Duik_api_fordoc.jsxinc, line 7028

Returns:
The content
Type: `string`

#### # static saveDialog(prompt, filteropt, defaultExtensionopt) → {File|null}

Shows the default save file dialog and returns the file selected by the user. If the user ommits the extension, the default extension will be appended (Mac OS fix).

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`prompt` | `string` |  |  | The prompt text, displayed if the dialog allows a prompt.
`filter` | `string` | <optional> | '' | The file type filter (windows only)
`defaultExtension` | `string` | <optional> | '' | The default extension

View Source Duik_api_fordoc.jsxinc, line 7269

Returns:
The file or null if the user cancels
Type: `File` | `null`

#### # static saveJSON(obj, file) → {boolean}

Saves a js object to a JSON file

##### Parameters:

Name | Type | Description
--- | --- | ---
`obj` | `Object` | The object to save
`file` | `File` | `string` | The file or URI

View Source Duik_api_fordoc.jsxinc, line 7145

Returns:
true if the file has been correctly written
Type: `boolean`

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

Encodes a file to a base64 string.

##### Parameters:

Name | Type | Description
--- | --- | ---
`file` | `string` | `File` | The file or its path

View Source Duik_api_fordoc.jsxinc, line 7198

Returns:
The base64 string
Type: `string`

#### # static write(file, content, appendopt, encodingopt) → {boolean}

Writes a text file

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`file` | `File` |  |  | The file
`content` | `string` |  |  | The content to write
`append` | `boolean` | <optional> | false | Appends instead of replacing
`encoding` | `string` | <optional> | 'UTF-8' | The text encoding

View Source Duik_api_fordoc.jsxinc, line 7064

Returns:
true if the file has been correctly written
Type: `boolean`

#### # static writeln(file, content, appendopt, encodingopt) → {boolean}

Writes a line in a text file

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`file` | `File` |  |  | The file
`content` | `string` |  |  | The content to write
`append` | `boolean` | <optional> | false | Appends instead of replacing
`encoding` | `string` | <optional> | 'UTF-8' | The text encoding

View Source Duik_api_fordoc.jsxinc, line 7097

Returns:
true if the file has been correctly written
Type: `boolean`