/**
* Creates an object that represents a folder or a file in the virtual file-system. The file may or may not already exist.
* @constructor
* @param {String} path Path of file/folder in the virtual file-system.
*
* @classdesc
* Represents a folder or a file in the virtual file-system. This file/folder may not yet exist.
*
* To read an existing file:
* ```
* var myFile = new File("/mydir/myfile.txt");
* var content = myFile.readText();
* ```
*
* To create a new file and write to it:
* ```
* var myFile = new File("/mydir/myfile.txt");
* myFile.writeText("Hello world");
* ```
*
* To get a list of files in a folder:
* ```
* var myFolder = new File("/mydir");
* var files = myFolder.getFiles();
* ```
*
* To create a new folder:
* ```
* var myFolder = new File("/mydir");
* myFolder.createFolder();
* ```
*
* To write an object to a JSON file and read it back again:
* ```
* var obj1 = { name: "Fred" };
* var objFile = new File("/mydir/myobject.json");
* objFile.writeObject(obj1);
* var obj2 = objFile.readObject();
* ```
*/
File = function (path) {
/**
* Date and time that this file/folder was last modified.
*
* @type {Date}
*/
this.modifiedTime = null;
/**
* Does the current user have permission to list this folder?
*
* @type {Boolean}
*/
this.canList = null;
/**
* Does the current user have permission to read this file?
*
* @type {Boolean}
*/
this.canRead = null;
/**
* Does the current user have permission to write to this file?
*
* @type {Boolean}
*/
this.canWrite = null;
/**
* Is this a folder?
*
* @type {Boolean}
*/
this.isFolder = null;
/**
* Is this an empty folder? Throws an exception if it's not a folder.
*
* @type {Boolean}
*/
this.isFolderEmpty = null;
/**
* Is this a file?
*
* @type {Boolean}
*/
this.isFile = null;
/**
* Is this file an executable?
*
* @type {Boolean}
*/
this.isExecutable = null;
/**
* Is the length of this file known?
*
* @type {Boolean}
*/
this.isLengthKnown = null;
/**
* Is this file a folder in the virtual file-system?
*
* @type {Boolean}
*/
this.isVirtualFileSystemFolder = null;
/**
* Length of the file in bytes.
*
* @type {Number}
*/
this.length = null;
/**
* Extension of the file.
*
* @type {String}
*/
this.extension = null;
/**
* The absolute path of the file in CompleteFTP's virtual file-system.
* For example, by default the `fullPath` of the home-folder of the user `NewUser1` is `/Home/NewUser1`.
*
* @type {String}
*/
this.fullPath = null;
/**
* The absolute path of the file in the adapter file-system (usually Windows).
* For example, the `adapterAbsolutePath` of `/Home` is
* `C:\ProgramData\Enterprise Distributed Technologies\Complete FTP\Users`
* (by default).
*
* @type {String}
*/
this.adapterAbsolutePath = null;
/**
* The name of the file.
*
* @type {String}
*/
this.name = null;
/**
* Does this file or folder exist?
*
* @method
* @return {Boolean}
*/
this.exists = function () { }
/**
* Copy this file to the given destination.
*
* @method
* @param {String} toPath Path to copy this file to.
*/
this.copyTo = function (toPath) { }
/**
* Create a folder at the path represented by this File object.
*
* @method
*/
this.createFolder = function () { }
/**
* Delete the file or folder at the path represented by this File object.
*
* @method
*/
this.remove = function () { }
/**
* Delete the folder at the path represented by this File object. Fails if this is a file.
*
* @method
* @param {String} [recursive=false] Remove all files and subfolders of the folder as well.
*/
this.removeFolder = function (recursive) { }
/**
* Delete the file at the path represented by this File object. Fails if this is a folder.
*
* @method
*/
this.removeFile = function () { }
/**
* Return a File object representing the parent-folder of this File object.
*
* @method
* @return {File}
*/
this.getParent = function () { }
/**
* Move this file to the given path.
*
* @method
* @param {String} toPath Path to move this file to.
*/
this.moveTo = function (toPath) { }
/**
* Returns an array of File objects representing the contents of this folder.
* Throws an exception if this File object is not a folder.
*
* @method
* @return {File[]}
*/
this.getFiles = function () { }
/**
* Rename the current file to the given name.
*
* @method
* @param {String} newName New name of file.
* @return {File} New File object for the renamed file.
*/
this.rename = function (newName) { }
/**
* Tries to read from the file. This differs from using canRead, which only checks permissions
* without attempting the operation.
*
* @method
* @return {Boolean} ``true`` if the read operation was successful and ``false`` otherwise.
*/
this.testRead = function() { }
/**
* Test to see if a folder can be listed (without listing all the files).
*
* @method
* @return {Boolean} ``true`` if the listing operation was successful and ``false`` otherwise.
*/
this.testGetFiles = function() { }
/**
* Returns the contents of this file as a string. This only works for files up to 100kB.
*
* @method
* @return {String}
*/
this.readText = function () { }
/**
* Write the given text to this file.
*
* @method
* @param {String} text Text to write to the file.
* @return {void}
*/
this.writeText = function (text) { }
/**
* Append the given text to this file.
*
* @method
* @param {String} text Text to append to the file.
* @return {void}
*/
this.appendText = function (text) { }
/**
* Returns the given number of lines (or all lines if numLines=0) as an array of strings.
*
* @method
* @param numLines
* @return {String[]}
*/
this.readLines = function (numLines) { }
/**
* Parses the contents of the file as JSON and returns a Javascript object. This only works for files up to 100kB.
*
* @method
* @return {Object}
*/
this.readObject = function () { }
/**
* Reads the contents of the file and returns it as a base64 encoded string.
* This only works for files up to 100kB.
*
* @method
* @return {String} base64 encoded string containing contents of file.
*/
this.readBase64 = function () { }
/**
* Parses the given base64-encoded string and writes the result to the file.
*
* @method
* @param {String} base64String base64 encoding of what is to be written to the file.
* @return {void}
*/
this.writeBase64 = function (base64String) { }
/**
* Write the given object to the file in JSON format.
*
* @method
* @param {String} object Object to write to the file.
* @return {void}
*/
this.writeObject = function (object) { }
/**
* Create an empty file at the location defined by this File object.
*
* @method
*/
this.createFile = function () { }
/**
* Get the URL that this file is accessible at.
*
* @method
* @return {String}
*/
this.toURL = function () { }
/**
* Unzip this file to the destination folder.
*
* @method
* @param {String} destinationFolder Virtual file-system path of folder where the file should be unzipped.
* @param {Boolean} overwrite If true then any existing files are overwritten
* otherwise an exception is thrown if a file is in the way.
*/
this.unzip = function (destinationFolder, overwrite) { }
}