File

File

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();

Constructor

new File(path)

Description:
  • Creates an object that represents a folder or a file in the virtual file-system. The file may or may not already exist.

Source:
Parameters:
Name Type Description
path String

Path of file/folder in the virtual file-system.

Members

adapterAbsolutePath :String

Description:
  • 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).

Source:

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

canList :Boolean

Description:
  • Does the current user have permission to list this folder?

Source:

Does the current user have permission to list this folder?

Type:
  • Boolean

canRead :Boolean

Description:
  • Does the current user have permission to read this file?

Source:

Does the current user have permission to read this file?

Type:
  • Boolean

canWrite :Boolean

Description:
  • Does the current user have permission to write to this file?

Source:

Does the current user have permission to write to this file?

Type:
  • Boolean

extension :String

Description:
  • Extension of the file.

Source:

Extension of the file.

Type:
  • String

fullPath :String

Description:
  • 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.

Source:

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

isExecutable :Boolean

Description:
  • Is this file an executable?

Source:

Is this file an executable?

Type:
  • Boolean

isFile :Boolean

Description:
  • Is this a file?

Source:

Is this a file?

Type:
  • Boolean

isFolder :Boolean

Description:
  • Is this a folder?

Source:

Is this a folder?

Type:
  • Boolean

isFolderEmpty :Boolean

Description:
  • Is this an empty folder? Throws an exception if it's not a folder.

Source:

Is this an empty folder? Throws an exception if it's not a folder.

Type:
  • Boolean

isLengthKnown :Boolean

Description:
  • Is the length of this file known?

Source:

Is the length of this file known?

Type:
  • Boolean

isVirtualFileSystemFolder :Boolean

Description:
  • Is this file a folder in the virtual file-system?

Source:

Is this file a folder in the virtual file-system?

Type:
  • Boolean

length :Number

Description:
  • Length of the file in bytes.

Source:

Length of the file in bytes.

Type:
  • Number

modifiedTime :Date

Description:
  • Date and time that this file/folder was last modified.

Source:

Date and time that this file/folder was last modified.

Type:
  • Date

name :String

Description:
  • The name of the file.

Source:

The name of the file.

Type:
  • String

Methods

appendText(text) → {void}

Description:
  • Append the given text to this file.

Source:
Parameters:
Name Type Description
text String

Text to append to the file.

Returns:
Type
void

copyTo(toPath)

Description:
  • Copy this file to the given destination.

Source:
Parameters:
Name Type Description
toPath String

Path to copy this file to.

createFile()

Description:
  • Create an empty file at the location defined by this File object.

Source:

createFolder()

Description:
  • Create a folder at the path represented by this File object.

Source:

exists() → {Boolean}

Description:
  • Does this file or folder exist?

Source:
Returns:
Type
Boolean

getFiles() → {Array.<File>}

Description:
  • Returns an array of File objects representing the contents of this folder. Throws an exception if this File object is not a folder.

Source:
Returns:
Type
Array.<File>

getParent() → {File}

Description:
  • Return a File object representing the parent-folder of this File object.

Source:
Returns:
Type
File

moveTo(toPath)

Description:
  • Move this file to the given path.

Source:
Parameters:
Name Type Description
toPath String

Path to move this file to.

readBase64() → {String}

Description:
  • Reads the contents of the file and returns it as a base64 encoded string.
    This only works for files up to 100kB.

Source:
Returns:

base64 encoded string containing contents of file.

Type
String

readLines(numLines) → {Array.<String>}

Description:
  • Returns the given number of lines (or all lines if numLines=0) as an array of strings.

Source:
Parameters:
Name Type Description
numLines
Returns:
Type
Array.<String>

readObject() → {Object}

Description:
  • Parses the contents of the file as JSON and returns a Javascript object. This only works for files up to 100kB.

Source:
Returns:
Type
Object

readText() → {String}

Description:
  • Returns the contents of this file as a string. This only works for files up to 100kB.

Source:
Returns:
Type
String

remove()

Description:
  • Delete the file or folder at the path represented by this File object.

Source:

removeFile()

Description:
  • Delete the file at the path represented by this File object. Fails if this is a folder.

Source:

removeFolder(recursiveopt)

Description:
  • Delete the folder at the path represented by this File object. Fails if this is a file.

Source:
Parameters:
Name Type Attributes Default Description
recursive String <optional>
false

Remove all files and subfolders of the folder as well.

rename(newName) → {File}

Description:
  • Rename the current file to the given name.

Source:
Parameters:
Name Type Description
newName String

New name of file.

Returns:

New File object for the renamed file.

Type
File

testGetFiles() → {Boolean}

Description:
  • Test to see if a folder can be listed (without listing all the files).

Source:
Returns:

true if the listing operation was successful and false otherwise.

Type
Boolean

testRead() → {Boolean}

Description:
  • Tries to read from the file. This differs from using canRead, which only checks permissions without attempting the operation.

Source:
Returns:

true if the read operation was successful and false otherwise.

Type
Boolean

toURL() → {String}

Description:
  • Get the URL that this file is accessible at.

Source:
Returns:
Type
String

unzip(destinationFolder, overwrite)

Description:
  • Unzip this file to the destination folder.

Source:
Parameters:
Name Type Description
destinationFolder String

Virtual file-system path of folder where the file should be unzipped.

overwrite Boolean

If true then any existing files are overwritten otherwise an exception is thrown if a file is in the way.

writeBase64(base64String) → {void}

Description:
  • Parses the given base64-encoded string and writes the result to the file.

Source:
Parameters:
Name Type Description
base64String String

base64 encoding of what is to be written to the file.

Returns:
Type
void

writeObject(object) → {void}

Description:
  • Write the given object to the file in JSON format.

Source:
Parameters:
Name Type Description
object String

Object to write to the file.

Returns:
Type
void

writeText(text) → {void}

Description:
  • Write the given text to this file.

Source:
Parameters:
Name Type Description
text String

Text to write to the file.

Returns:
Type
void