NGDesktop File (ref)
Last updated
Was this helpful?
Last updated
Was this helpful?
(part of package '')
You can access it in code via: plugins.ngdesktopfile
Synchronously append data to a file, creating the file if it does not yet exist.
Parameters:
{} path - file's full path
{} text - text to be added
{} [encoding] - default utf8
Returns: True if the data was successfully appended to the file; otherwise, false.
Clears the directory where temporary files are stored (e.g. when using writeTempFileSync(bytes)).
Returns: True if the temporary files directory was successfully cleared; otherwise, false.
Synchronously copies src to dest. By default, dest is overwritten if it already exists.
Parameters:
Synchronously creates a folder, including any necessary but nonexistent parent folders.
Parameters:
Deletes the given file, optionally calling the error callback when unsuccessful
Parameters:
Delete the given file, returning a boolean indicating success or failure
Parameters:
Synchronously deletes a folder, fails when folder is not empty
Parameters:
Test whether or not the given path exists by checking with the file system. It returns true if the path exists, false otherwise.
Parameters:
Return a 'stats' object containing related file's information's. Please use forward slashes (/) instead of backward slashes in the path
Parameters:
Retrieves the path to a special directory or file associated with the given name.
Parameters:
Verify readonly status on the specified path. Returns true for readonly otherwise false
Parameters:
Returns the home dir of the user like c:/users/[username] under windows. Will return always a both with forward slashes.
returns an array of filenames that are in the given path. Please use forward slashes (/) instead of backward slashes.
Parameters:
Opens a file specified at the given path on the client. It will open it in the desktop's default manner. This path must exist on the client's machine, you can't open a file with a path pointing to a file on the server; use writeFile() first to write it to the clients machine.
If it fails, it returns a string containing the error message corresponding to the failure. If the file has been successfully opened, it will return an empty string.
Parameters:
Reads the given bytes of a path, the callback is a function that will get as parameters the 'path' as a String and the 'file' as a JSUpload object If an error is happening in the browser then this error will be given as a 3rd argyument and the second file argument is then null. If the path is missing or contain only the file name then the native system dialog for opening files it is called. Please use forward slashes (/) instead of backward slashes in the path/filename
Parameters:
Reads and returns the content of the given file This will throw an error if something goes wrong on the client, the error is then the message string. So this needs to be try/catched
Parameters:
Reads and returns the text of the given path/filename
Parameters:
Synchronously rename file at oldPath to the pathname provided as newPath. In the case that newPath already exists, it will be overwritten.
Parameters:
Select a folder and pass its path to the callback.
Parameters:
Return the selected folder.
Parameters:
Return the selected file.
Parameters:
Set permisions to the specified file. If readOnly parameter is false, the file permisions flags will be set to read/write mode
Parameters:
Shows a file open dialog and calls the callback with the selected file path(s).
For the options object see https://www.electronjs.org/docs/api/dialog#dialogshowopendialogbrowserwindow-options
The core options are:
title: String the dialog title
defaultPath: String the default (starting) path
buttonLabel: String custom label for the confirmation button, when left empty the default label will be used.
filters: Array<{name: String, extensions: Array<String>}> an array of file filters (e.g. [{ name: 'Images', extensions: ['jpg', 'png', 'gif'] }])
properties: an Array of property keywords such as:
openFile
- Allow files to be selected.
openDirectory
- Allow directories to be selected.
multiSelections
- Allow multiple paths to be selected.
Parameters:
Shows a file open dialog and returns the selected file path(s).
To not block any process, showOpenDialog with a callback method is preferred over this method.
For the options object see https://www.electronjs.org/docs/api/dialog#dialogshowopendialogsyncbrowserwindow-options
Core options are:
title: String the dialog title
defaultPath: String the default (starting) path
buttonLabel: String custom label for the confirmation button, when left empty the default label will be used.
filters: Array<{name: String, extensions: Array<String>}> an array of file filters (e.g. [{ name: 'Images', extensions: ['jpg', 'png', 'gif'] }])
properties: an Array of property keywords such as:
openFile
- Allow files to be selected.
openDirectory
- Allow directories to be selected.
multiSelections
- Allow multiple paths to be selected.
Parameters:
Shows a file save dialog and calls the callback method with the file path.
For the options object see https://www.electronjs.org/docs/api/dialog#dialogshowsavedialogbrowserwindow-options
Core options are:
title: String the dialog title
defaultPath: String - absolute directory path, absolute file path, or file name to use by default.
buttonLabel: String - custom label for the confirmation button, when left empty the default label will be used.
filters: Array<{name: String, extensions: Array<String>}> - an array of file filters (e.g. [{ name: 'Images', extensions: ['jpg', 'png', 'gif'] }])
Parameters:
Shows a file save dialog.
To not block any process, showSaveDialog with a callback method is preferred over this method.
For the options object see https://www.electronjs.org/docs/api/dialog#dialogshowsavedialogsyncbrowserwindow-options
Core options are:
title: String the dialog title
defaultPath: String - absolute directory path, absolute file path, or file name to use by default.
buttonLabel: String - custom label for the confirmation button, when left empty the default label will be used.
filters: Array<{name: String, extensions: Array<String>}> - an array of file filters (e.g. [{ name: 'Images', extensions: ['jpg', 'png', 'gif'] }])
Parameters:
Returns the tmp directory of the client machine. Will return always a both with forward slashes.
Stop watching a directory found at the given path.
Parameters:
Removes the watch to the file that was added by the watchFile() function. Please use forward slashes (/) instead of backward slashes in the path/filename
Parameters:
Watches a directory for changes at the given path.
Parameters:
Watches a give path, that should represent a file, for modifications. Please use forward slashes (/) instead of backward slashes in the path/filename
Parameters:
Writes the given bytes to the path; if the path has sub-directories that are not there, then those are created. If the path is missing or contains only the file name, then the native system dialog for saving files is used.
When done, the optional callback is called with the written path (as a string), or 'error'. An optional passThru object is also passed back to the callback function. Please use forward slashes (/) instead of backward slashes in path/filename.
Parameters:
Writes text to the given path/filename
Parameters:
A synchronous way to write bytes to a temporary file with a unique pseudo-random name, in a directory for temporary files. This directory will be cleared when the ngDesktop window is closed or when clearTempFiles() is called.
The function returns the path of the created file as a string.
Parameters:
Represents file system statistics for a file or directory. scripting type: CustomType<ngdesktopfile.stats>
atimeMs
The last access time in milliseconds.
birthtimeMs
The birth time (creation time) in milliseconds.
blksize
The block size for file system I/O.
blocks
The number of blocks allocated for the file.
ctimeMs
The last status change time in milliseconds.
dev
The device ID.
gid
The group ID of the file's owner.
ino
The inode number.
isBlockDevice
Indicates if the file is a block device.
Default Value: false
isCharacterDevice
Indicates if the file is a character device.
Default Value: false
isDirectory
Indicates if the path is a directory.
Default Value: false
isFIFO
Indicates if the file is a FIFO (named pipe).
Default Value: false
isFile
Indicates if the path is a regular file.
Default Value: false
isSocket
Indicates if the file is a socket.
Default Value: false
isSymbolicLink
Indicates if the file is a symbolic link.
Default Value: false
mode
The file mode (permissions).
mtimeMs
The last modification time in milliseconds.
nlink
The number of hard links.
rdev
The device ID (if the file is a special file).
uid
The user ID of the file's owner.
{} src - source filepath to copy
{} dest - destination filepath of the copy operation
{} [overwriteDest] - default true
Returns: True if the file was successfully copied; otherwise, false.
{} path - folders full path
Returns: True if the folder was successfully created; otherwise, false.
{} path The full path of the file to be deleted.
{} [errorCallback] An optional callback function that will be invoked if the deletion fails.
{} path The full path of the file to be deleted.
Returns: True if the file was successfully deleted; otherwise, false.
{} path - folders full path
Returns: True if the folder was successfully deleted; otherwise, false.
{} path - file's full path
Returns: True if the specified path exists in the file system; otherwise, false.
{} path The full path of the file whose statistics are to be retrieved.
Returns: An object containing file-related information.
{} path {('home' | 'desktop' | 'temp' | 'documents' | 'downloads')} name - The name of the directory or file.
Returns: The path to a special directory or file associated with the name, or an empty string if the name is not one of the allowed values.
{} path - directory's full path
Returns: True if the file or folder is read-only; otherwise, false.
Returns: The full path of the user's home directory, using forward slashes.
{} path The full path of the directory to list files from.
Returns: An array of filenames present in the specified directory path.
{} path - file's full path on the client.
Returns: An empty string if the file was successfully opened or a string containing the error message corresponding to the failure otherwise.
{} callback A function that receives the file path as a string and the file content as a JSUpload object or a 3rd argument with the error message.
{} [path] The full path of the file to read. If omitted or only a filename is provided, a file open dialog will be shown.
{} [path] The full path of the file to read.
Returns: The content of the file.
{} path The full path of the file to read.
{} [encoding] Optional, default 'utf8'
Returns: The content of the file as a string, or an empty string if the file could not be read.
{} oldPath - old file full path
{} newPath - new file full path
Returns: True if the file was successfully renamed; otherwise, false.
{} callback A function that receives the selected folder's path as an argument.
{} [path] The initial path to open the directory selection dialog at.
Returns: The full path of the selected folder, or an empty string if no folder was selected.
{} [path] The initial path to open the file selection dialog at.
Returns: The full path of the selected file, or an empty string if no file was selected.
{} path - File path
{} flag If true, sets the file to read-only mode; if false, allows read/write access.
Returns: True if the file permissions were successfully updated; otherwise, false.
{} callback A function that receives the selected file path(s) as an argument.
{} [options] {{title: String=, defaultPath: String=, buttonLabel: String=, filters: Array<{name: String, extensions: Array<String>}>=, properties: Array<String>}}
{} [options] {{title: String=, defaultPath: String=, buttonLabel: String=, filters: Array<{name: String, extensions: Array<String>}>=, properties: Array<String>}} [options]
Returns: An array of selected file or directory paths, or an empty array if no selection was made.
{} callback A function that receives the selected file path as an argument.
{} [options] {{title: String=, defaultPath: String=, buttonLabel: String=, filters: Array<{name: String, extensions: Array<String>}>=}} [options]
{} [options] {{title: String=, defaultPath: String=, buttonLabel: String=, filters: Array<{name: String, extensions: Array<String>}>=}}
Returns: The full path of the selected file if the user confirmed the dialog, or an empty string if the dialog was canceled.
Returns: The full path of the system's temporary directory, using forward slashes.
{} path The full path of the directory to stop watching for changes.
{} path The full path of the file to stop watching for modifications.
{} path - directory's full path
{} callback - the callback method to be executed
{} path The full path of the file to watch for modifications.
{} callback A function that will be triggered when the file is modified.
{} path The full path where the file will be written. If only a filename is provided, a save dialog will be shown.
{} bytes The binary data to write to the file.
{} [callback] An optional function that receives the written file path or an 'error' string if the operation fails.
{} [passThru] An optional object that will be passed back to the callback function.
{} path The full path of the file where the text will be written.
{} text_data The text content to write into the file.
{} [encoding] Encoding code (default 'utf8')
Returns: True if the text was successfully written to the file; otherwise, false.
{} bytes The binary data to be written to the temporary file.
Returns: The full path of the created temporary file.
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type:
Type: