NGDesktop File (ref)
(part of package 'NGDesktop File')
You can access it in code via: plugins.ngdesktopfile
API
appendToTXTFile(path,text,encoding)
Synchronously append data to a file, creating the file if it does not yet exist.
Parameters:
Returns: boolean
clearTempFiles()
Clears the directory where temporary files are stored (e.g. when using writeTempFileSync(bytes)). Returns true if successful.
Returns: boolean
copyFile(src,dest,overwriteDest)
Synchronously copies src to dest. By default, dest is overwritten if it already exists.
Parameters:
Returns: boolean
createFolder(path)
Synchronously creates a folder, including any necessary but nonexistent parent folders.
Parameters:
{string} path - folders full path
Returns: boolean
deleteFile(path,errorCallback)
Deletes the given file, optionally calling the error callback when unsuccessful
Parameters:
deleteFileSync(path)
Delete the given file, returning a boolean indicating success or failure
Parameters:
{string} path Path
Returns: boolean
deleteFolder(path)
Synchronously deletes a folder, fails when folder is not empty
Parameters:
{string} path - folders full path
Returns: boolean
exists(path)
Test whether or not the given path exists by checking with the file system. It returns true if the path exists, false otherwise.
Parameters:
{string} path - file's full path
Returns: boolean
getFileStats(path)
Return a 'stats' object containing related file's information's. Please use forward slashes (/) instead of backward slashes in the path
Parameters:
{string} path
Returns: stats
getPath(path)
Retrieves the path to a special directory or file associated with the given name.
Parameters:
{string} path - The name of the directory or file.
Returns: string ** 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.
getReadOnly(path)
Verify readonly status on the specified path. Returns true for readonly otherwise false
Parameters:
{string} path ** path - directory's full path
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(path)
returns an array of filenames that are in the given path. Please use forward slashes (/) instead of backward slashes.
Parameters:
{string} path
Returns: string[]
openFile(path)
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:
{string} path - file's full path on the client.
Returns: string An empty string if the file was successfully opened or a string containing the error message corresponding to the failure otherwise.
readFile(callback,path)
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(path)
Reads and returns the content of the given file
Parameters:
{string} [path] Path
Returns: object
readTXTFileSync(path,encoding)
Reads and returns the text of the given path/filename
Parameters:
Returns: string
renameFile(oldPath,newPath)
Synchronously rename file at oldPath to the pathname provided as newPath. In the case that newPath already exists, it will be overwritten.
Parameters:
Returns: boolean
selectDirectory(callback)
Select a folder and pass its path to the callback.
Parameters:
{function} callback
selectDirectorySync(path)
Return the selected folder.
Parameters:
{string} [path]
Returns: string
selectFileSync(path)
Return the selected file.
Parameters:
{string} [path]
Returns: string
setReadOnly(path,flag)
Set permisions to the specified file. If readOnly parameter is false, the file permisions flags will be set to read/write mode
Parameters:
Returns: object
showOpenDialog(callback,options)
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:
showOpenDialogSync(options)
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:
{object} [options] >=, properties: Array<String>}} [options]
Returns: string[] ** <Array<String>}
showSaveDialog(callback,options)
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:
showSaveDialogSync(options)
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:
{object} [options] >=}} [options]
Returns: string
tmpDir()
Returns the tmp directory of the client machine. Will return always a both with forward slashes.
Returns: string
unwatchDir(path)
Stop watching a directory found at the given path.
Parameters:
{string} path
unwatchFile(path)
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:
{string} path
watchDir(path,callback)
Watches a directory for changes at the given path.
Parameters:
watchFile(path,callback)
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(path,bytes,callback,passThru)
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:
writeTXTFileSync(path,text_data,encoding)
Writes text to the given path/filename
Parameters:
Returns: boolean
writeTempFileSync(bytes)
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:
{byte[]} bytes Bytes
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