DuAEF.DuJS.Fs

JavaScript File System related methods

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 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 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 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 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