DuAEF.DuJS.Fs

JavaScript File System related methods

Namespaces

ImageSequence

Members

static duaefData :Folder

The folder where DuAEF stores its data, a "DuAEF" subfolder of DuAEF.DuJS.Fs.userData

static userData :Folder

The default user data.
Replaces the Folder.userData provided by ESTK which does not work properly with mac network sessions.
In windows, the value of %APPDATA% ("C:\Documents and Settings\username\Application Data")
In Mac OS, "~/Library/Application Support"

Methods

static fileExists(pathopt) → {boolean}

Checks if the given path exists
Parameters:
Name Type Attributes Description
path string <optional>
The file path
Returns:
boolean - True or false

static fixFileName(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
Returns:
string - The fixed filename

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
Returns:
String - The basename
Example
DuAEF.DuJS.Fs.getBasename(new File("D:/code/open/Duik/shape.test")) // "shape"
DuAEF.DuJS.Fs.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
Returns:
String - The extension
Example
DuAEF.DuJS.Fs.getExtension(new File("D:/code/open/Duik/shape.other.test")) // "test"
DuAEF.DuJS.Fs.getExtension("D:/code/open/Duik/shape.test") // "test"

static getFilesInFolder(folder, filteropt) → {Array}

Recursively gets all files in a folder using a name filter Returns an array of File objects.
Parameters:
Name Type Attributes Default Description
folder Folder The Folder
filter string | function <optional>
"*" A search mask for file names, specified as a string or a function. A mask string can contain question mark (?) and asterisk (*) wild cards. Default is "*", which matches all file names. Can also be the name of a function that takes a File or Folder object as its argument. It is called for each file or folder found in the search; if it returns true, the object is added to the return array.
Returns:
Array - The files found.

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
Returns:
String - The basename
Example
DuAEF.DuJS.Fs.getName(new File("D:\\code\\open\\Duik\\shape test.test")) // "shape test.test"
DuAEF.DuJS.Fs.getName("D:/code/open/Duik/other shape.test") // "other shape.test"

static incrementFileName(file) → {string}

Increments the last number before the extension in a filename
Parameters:
Name Type Description
file File The file
Returns:
string - The incremented fileName

static isFile(file) → {boolean}

Checks if an object is a File
Parameters:
Name Type Description
file * The object to check
Returns:
boolean - true if this object is an instance of Folder

static isFolder(file) → {boolean}

Checks if an object is a Folder
Parameters:
Name Type Description
file * The object to check
Returns:
boolean - true if this object is an instance of Folder

static newUniqueFileName(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
Returns:
string - The unique name, with a new number at the end if needed.

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

static parseJSON(file) → {Object|null}

Parses a JSON file
Parameters:
Name Type Description
file File The file
Returns:
Object | null - The content or null if the file couldn't be parsed

static readFile(file, encodingopt) → {string}

Reads a whole file and return its content
Parameters:
Name Type Attributes Default Description
file File The file
encoding string <optional>
'UTF-8' The text encoding
Returns:
string - The content

static readFirstLine(file) → {string}

Reads the first line of a file and return its content
Parameters:
Name Type Description
file File The file
Returns:
string - The content

static saveFileDialog(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
Returns:
File | null - The file or null if the user cancels

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
Returns:
boolean - true if the file has been correctly written

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
Returns:
String - The new path

static wipeFolder(folder)

Recursively remove all content from folder and the folder itself. Warning, this does not move files to the recycle bin and can not be undone.
Parameters:
Name Type Description
folder string | Folder the path or Folder object to wipe.

static writeTextFile(file, content, appendopt, encodingopt)

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