NGDesktop File (ref)
(part of package 'NGDesktop File')
You can access it in code via: plugins.ngdesktopfile
API
appendToTXTFile
Synchronously append data to a file, creating the file if it does not yet exist.
@param {String} path - file's full path @param {String} text - text to be added @param {String} [encoding] - default utf8 @return {boolean}
Parameters:
Returns: boolean
clearTempFiles
Clears the directory where temporary files are stored (e.g. when using writeTempFileSync(bytes)). Returns true if successful.
@return {boolean}
Returns: boolean
copyFile
Synchronously copies src to dest. By default, dest is overwritten if it already exists.
@param {String} src - source filepath to copy @param {String} dest - destination filepath of the copy operation @param {Boolean} [overwriteDest] - default true @return {boolean}
Parameters:
Returns: boolean
createFolder
Synchronously creates a folder, including any necessary but nonexistent parent folders.
@param {String} path - folders full path @return {boolean}
Parameters:
path string
Returns: boolean
deleteFile
Deletes the given file, optionally calling the error callback when unsuccessful
@param {String} path @param {Function} [errorCallback]
Parameters:
deleteFileSync
Delete the given file, returning a boolean indicating success or failure
@param {String} path @return {boolean}
Parameters:
path string
Returns: boolean
deleteFolder
Synchronously deletes a folder, fails when folder is not empty
@param {String} path - folders full path @return {boolean}
Parameters:
path string
Returns: boolean
exists
Test whether or not the given path exists by checking with the file system. It returns true if the path exists, false otherwise.
@param {String} path - file's full path @return {boolean}
Parameters:
path string
Returns: boolean
getFileStats
Return a 'stats' object containing related file's information's. Please use forward slashes (/) instead of backward slashes in the path
@return {stats}
Parameters:
path string
Returns: stats
getPath
Retrieves the path to a special directory or file associated with the given name.
@param {('home' | 'desktop' | 'temp' | 'documents' | 'downloads')} name - The name of the directory or file. @return s {String} 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.
Parameters:
path string
Returns: string
getReadOnly
Verify readonly status on the specified path. Returns true for readonly otherwise false
@param path - directory's full path @return {boolean}
Parameters:
path string
Returns: boolean
homeDir
Returns the home dir of the user like c:/users/[username] under windows. Will return always a both with forward slashes.
Returns: string
listDir
returns an array of filenames that are in the given path. Please use forward slashes (/) instead of backward slashes.
Parameters:
path string
Returns: string[]
openFile
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.
@param {String} path - file's full path on the client. @return {String} an empty string if the file was successfully opened or a string containing the error message corresponding to the failure otherwise.
Parameters:
path string
Returns: string
readFile
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 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:
readFileSync
Reads and returns the content of the given file
@param {String} path @return {JSUpload}
Parameters:
path string (optional)
Returns: object
readTXTFileSync
Reads and returns the text of the given path/filename
@param {String} path @param {String} [encoding] optional, default 'utf8' @return {String}
Parameters:
Returns: string
renameFile
Synchronously rename file at oldPath to the pathname provided as newPath. In the case that newPath already exists, it will be overwritten.
@param {String} oldPath - old file full path @param {String} newPath - new file full path @return {boolean}
Parameters:
Returns: boolean
selectDirectory
Select a folder and pass its path to the callback.
Parameters:
callback function
selectDirectorySync
Return the selected folder.
Parameters:
path string (optional)
Returns: string
selectFileSync
Return the selected file.
Parameters:
path string (optional)
Returns: string
setReadOnly
Set permisions to the specified file. If readOnly parameter is false, the file permisions flags will be set to read/write mode
@param path - file path @return {boolean}
Parameters:
Returns: object
showOpenDialog
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.
@param {Function} callback @param {{title: String=, defaultPath: String=, buttonLabel: String=, filters: Array<{name: String, extensions: Array<String>}>=, properties: Array<String>}} [options]
Parameters:
showOpenDialogSync
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.
@param {{title: String=, defaultPath: String=, buttonLabel: String=, filters: Array<{name: String, extensions: Array<String>}>=, properties: Array<String>}} [options] @return <Array<String>}
Parameters:
options object (optional)
Returns: string[]
showSaveDialog
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'] }])
@param {Function} callback @param {{title: String=, defaultPath: String=, buttonLabel: String=, filters: Array<{name: String, extensions: Array<String>}>=}} [options]
Parameters:
showSaveDialogSync
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'] }])
@param {{title: String=, defaultPath: String=, buttonLabel: String=, filters: Array<{name: String, extensions: Array<String>}>=}} [options] @return {String}
Parameters:
options object (optional)
Returns: string
tmpDir
Returns the tmp directory of the client machine. Will return always a both with forward slashes.
Returns: string
unwatchDir
Stop watching a directory found at the given path.
Parameters:
path string
unwatchFile
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:
path string
watchDir
Watches a directory for changes at the given path.
@param path - directory's full path @param callback - the callback method to be executed
Parameters:
watchFile
Watches a give path, that should represent a file, for modifications. Please use forward slashes (/) instead of backward slashes in the path/filename
Parameters:
writeFile
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:
path string bytes byte[] callback function (optional) passThru object (optional)
writeTXTFileSync
Writes text to the given path/filename
@param {String} path @param {String} text_data @param {String} [encoding] optional, default 'utf8' @return {boolean}
Parameters:
Returns: boolean
writeTempFileSync
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.
@param {Object} bytes @return {String}
Parameters:
bytes byte[]
Returns: string
Types
stats
scripting type: CustomType<ngdesktopfile.stats>
atimeMs
Type: long
birthtimeMs
Type: long
blksize
Type: long
blocks
Type: long
ctimeMs
Type: long
dev
Type: long
gid
Type: long
ino
Type: long
isBlockDevice
Type: boolean
Default Value: false
isCharacterDevice
Type: boolean
Default Value: false
isDirectory
Type: boolean
Default Value: false
isFIFO
Type: boolean
Default Value: false
isFile
Type: boolean
Default Value: false
isSocket
Type: boolean
Default Value: false
isSymbolicLink
Type: boolean
Default Value: false
mode
Type: long
mtimeMs
Type: long
nlink
Type: long
rdev
Type: long
uid
Type: long
Last updated