voltmx.io.File Namespace
The voltmx.io.File namespace provides functions and properties for doing various operations related on files, such as copying them, renaming them , deleting them, and so on.
Overview
Your app can create a File
object to represent files in the device’s file system and perform common operations on them. To create a new File
object , your app calls the voltmx.io.File
function. Alternatively, it can use the voltmx.io.FileSystem.getFile function to get an instance of a File
object.
File Properties:Name | Description |
---|---|
name: [type: String, ReadOnly] | Name of the file or directory |
fullPath: [type: String, ReadOnly] | Full absolute path of the file or directory |
parent: [type:voltmx.io.File, ReadOnly] | Returns the parent directory of this file. This property may return nil or a File object which can neither Readable or Writable, especially in case of Folders which are not accessible by the given Application context |
readable: [type: Boolean, ReadOnly] | Returns true if this file is readable |
writable: [type: Boolean, ReadOnly] | Returns true if this file is writable |
modificationTime: [type:Number, ReadOnly] | Returns the last modification time of the file in UTC |
size: [type:Number, ReadOnly | Returns the size of a file in number of bytes. |
The following function is often used in conjunction with the RawBytes object to read data of type RawBytes.
Functions
The voltmx.io.File namespace contains these functions: To use the copyTo, moveTo, remove, rename, createFile, createDirectory, read, and write File APIs, your app needs runtime permission from the end-user (to perform any of the action correspondent to a file). If you call any API without obtaining the permission, platforms automatically pops up a system permission dialog box with “Allow” and “Deny” options, asking the end-user to grant permission. This is applicable only for the Android platform.
If the end-user taps the “Allow” option, platform proceeds to access the underlying OS API. If the end-user taps the “Deny” option, the PermissionError exception is thrown with the 2300 error code, that means permission is denied.
voltmx.io.File.copyTo
copyTo API copies a file to the given destination path.
Syntax
Input Parameters
Parameter | Description |
---|---|
Path | path to the destination directory. |
newName (optional) | New name of the file/directory. Defaults to current name if unspecified. |
Example
Return Values
VoltMX.io.File returns a handle to the File object pointing to the destination file, if successful. If failure, then returns null.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.createDirectory
The createDirectory API creates a directory on the file system represented by this file object.
Syntax
Input Parameters
None
Example
Return Values
Boolean – true if the creation of directory is successful. False if directory already exists or could not be created.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.createFile
The createFile API creates a file on the file system represented by this file object.
Syntax
Input Parameters
None
Example
Return Values
Boolean – true if the creation of file is successful. False if file already exists or could not be created.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.exists
The exist API checks, if the file or directory exists on the file system represented by this file object.
Syntax
Input Parameters
None
Example
Return Values
Boolean – true if the file or directory exists on file system.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.getFilesList
The getFilesList API returns voltmx.io.FileList object representing the files and directories available under this file object directory.
Syntax
Input Parameters
None
Example
Return Values
voltmx.io.FileList – FileList object or null if this File is not identified as a directory.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.isDirectory
The isDirectory API checks, if this object represents a directory file on the file system.
Syntax
Input Parameters
None
Example
Return Values
Boolean – true, if this file object represents a directory, false otherwise.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.isFile
The isFile API checks, if this object represents a typical file on the file system but not a directory.
Syntax
Input Parameters
None
Example
Return Values
Boolean – true if this file object represents a file, false otherwise.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.moveTo
The moveTo API moves a file to the given destination path.
Syntax
Input Parameters
Parameter | Description |
---|---|
Path | path to the destination directory. |
newName (optional) | New name of the file/directory. Defaults to current name, if unspecified. |
Example
Return Values
VoltMX.io.File – returns a handle to File object pointing to destination file on success. Returns null on failure.
Exceptions
None
Platform Availability
Available to iOS, Android, and Windows platforms.
voltmx.io.File.read
The read API returns the voltmx.types.RawBytes of this file.
Syntax
Input Parameters
None
Example
Return Values
voltmx.types.RawBytes – rawbytes representing the content of the file.Returns null in case of non existent file.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
Note: RawBytes will hold a handle of File object that it represents. The file content is not actually loaded into memory.
voltmx.io.File.remove
The remove API deletes a file or a directory.
Syntax
Input Parameters
Parameter | Description |
---|---|
boolean | By default, this is false.True - deletes the folder and all its content recursively.False - if the directory is empty it shall be removed. |
deleteRecursive (optional) | Ignored in case of a file. |
Example
Return Values
None
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.rename
The rename API renames a file or a directory.
Syntax
Input Parameters
Parameter | Description |
---|---|
newname | new name for a file or a directory. |
Example
Return Values
Boolean – If successful, then boolean value is true,. Boolean value is false, if invalid file name or if the destination is a different directory than the current file.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.
voltmx.io.File.write
The write API writes the given content into the file.
Syntax
Input Parameters
Parameter | Description |
---|---|
Rawbytes/string | data to write of type text string or voltmx.types.RawBytes |
Append (optional) | true to append the data. Default is false, that means overrides the content. |
Example
Return Values
Boolean – true if success, false otherwise.
Exceptions
None
Platform Availability
Available for iOS, Android, and Windows platforms.