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.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
String | Path of file/folder in the virtual file-system. |
Properties
| Property | Type | Description |
|---|---|---|
| adapterAbsolutePath | String | The absolute path of the file in the adapter file-system (usually Windows). |
| canList | Boolean | Does the current user have permission to list this folder? . |
| canRead | Boolean | Does the current user have permission to read this file? . |
| canRemove | Boolean | Does the current user have permission to delete this file/folder? . |
| canRename | Boolean | Does the current user have permission to rename this file/folder? . |
| canWrite | Boolean | Does the current user have permission to write to this file? . |
| extension | String | Extension of the file. |
| fullPath | String | The absolute path of the file in CompleteFTP's virtual file-system. |
| isExecutable | Boolean | Is this file an executable? . |
| isFile | Boolean | Is this a file? . |
| isFolder | Boolean | Is this a folder? . |
| isFolderEmpty | Boolean | Is this an empty folder? Throws an exception if it's not a folder. |
| isLengthKnown | Boolean | Is the length of this file known? . |
| isVirtualFileSystemFolder | Boolean | Is this file a folder in the virtual file-system? . |
| length | Number | Length of the file in bytes. |
| modifiedTime | Date | Date and time that this file/folder was last modified. |
| name | String | The name of the file. |
| nameWithoutExtension | String | The name of the file without its extension. |
Methods
| Method | Returns | Description |
|---|---|---|
| appendText() | void | Append the given text to this file. |
| copyTo() | void | Copy this file to the given destination. |
| createFile() | void | Create an empty file at the location defined by this File object. |
| createFolder() | void | Create a folder at the path represented by this File object. |
| exists() | Boolean | Does this file or folder exist? . |
| getFiles() | Array.<File> | Returns an array of File objects representing the contents of this folder. |
| getParent() | File | Return a File object representing the parent-folder of this File object. |
| moveTo() | void | Move this file to the given path. |
| readBase64() | String | Reads the contents of the file and returns it as a base64 encoded string. |
| readLines() | Array.<String> | Returns the given number of lines (or all lines if numLines=0) as an array of strings. |
| readObject() | Object | Parses the contents of the file as JSON and returns a Javascript object. |
| readText() | String | Returns the contents of this file as a string. |
| remove() | void | Delete the file or folder at the path represented by this File object. |
| removeFile() | void | Delete the file at the path represented by this File object. |
| removeFolder() | void | Delete the folder at the path represented by this File object. |
| rename() | File | Rename the current file to the given name. |
| searchAbort() | void | Aborts an ongoing search. |
| searchContinue() | Object | Continues a previously started search, returning the next batch of results. |
| searchStart() | string | Begins a search for files and folders that match a specified pattern within the directory represented by this File object. |
| testGetFiles() | Boolean | Test to see if a folder can be listed (without listing all the files). |
| testRead() | Boolean | Tries to read from the file. |
| toURL() | String | Get the URL that this file is accessible at. |
| unzip() | void | Unzip this file to the destination folder. |
| writeBase64() | void | Parses the given base64-encoded string and writes the result to the file. |
| writeObject() | void | Write the given object to the file in JSON format. |
| writeText() | void | Write the given text to this file. |
Property Details
adapterAbsolutePath :String
- Description:
The absolute path of the file in the adapter file-system (usually Windows).
For example, theadapterAbsolutePathof/HomeisC:\ProgramData\Enterprise Distributed Technologies\Complete FTP\Users(by default).
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?
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?
Does the current user have permission to read this file?
Type:
- Boolean
canRemove :Boolean
- Description:
Does the current user have permission to delete this file/folder?
Does the current user have permission to delete this file/folder?
Type:
- Boolean
canRename :Boolean
- Description:
Does the current user have permission to rename this file/folder?
Does the current user have permission to rename this file/folder?
Type:
- Boolean
canWrite :Boolean
- Description:
Does the current user have permission to write to this file?
Does the current user have permission to write to this file?
Type:
- Boolean
extension :String
- Description:
Extension of the file.
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
fullPathof the home-folder of the userNewUser1is/Home/NewUser1.
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?
Is this file an executable?
Type:
- Boolean
isFile :Boolean
- Description:
Is this a file?
Is this a file?
Type:
- Boolean
isFolder :Boolean
- Description:
Is this a folder?
Is this a folder?
Type:
- Boolean
isFolderEmpty :Boolean
- Description:
Is this an empty folder? Throws an exception if it's not a folder.
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?
Is the length of this file known?
Type:
- Boolean
isVirtualFileSystemFolder :Boolean
- Description:
Is this file a folder in the virtual file-system?
Is this file a folder in the virtual file-system?
Type:
- Boolean
length :Number
- Description:
Length of the file in bytes.
Length of the file in bytes.
Type:
- Number
modifiedTime :Date
- Description:
Date and time that this file/folder was last modified.
Date and time that this file/folder was last modified.
Type:
- Date
name :String
- Description:
The name of the file.
The name of the file.
Type:
- String
nameWithoutExtension :String
- Description:
The name of the file without its extension.
The name of the file without its extension.
Type:
- String
Method Details
appendText(text) → {void}
- Description:
Append the given text to this file.
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.
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.
createFolder()
- Description:
Create a folder at the path represented by this File object.
exists() → {Boolean}
- Description:
Does this file or folder exist?
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.
Returns:
- Type
- Array.<File>
getParent() → {File}
- Description:
Return a File object representing the parent-folder of this File object.
Returns:
- Type
- File
moveTo(toPath)
- Description:
Move this file to the given path.
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.
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.
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.
Returns:
- Type
- Object
readText() → {String}
- Description:
Returns the contents of this file as a string. This only works for files up to 100kB.
Returns:
- Type
- String
remove()
- Description:
Delete the file or folder at the path represented by this File object.
removeFile()
- Description:
Delete the file at the path represented by this File object. Fails if this is a folder.
removeFolder(recursiveopt)
- Description:
Delete the folder at the path represented by this File object. Fails if this is a file.
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.
Parameters:
| Name | Type | Description |
|---|---|---|
newName |
String | New name of file. |
Returns:
New File object for the renamed file.
- Type
- File
searchAbort(id)
- Description:
Aborts an ongoing search. This is useful to free resources if the results of the search are no longer needed before it has completed.
Example
myFolder.searchAbort(searchId);
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | The unique identifier of the search, obtained from |
searchContinue(nextBatchSizeopt, id) → {Object}
- Description:
Continues a previously started search, returning the next batch of results. This method should be called repeatedly until all results have been retrieved.
Example
var results = myFolder.searchContinue(50, searchId);
if (results.hasMore) {
// More results available
}
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
nextBatchSize |
number |
<optional> |
100
|
The number of results to return in the next batch. The number of results returned by this invocation is determined by the previous call to searchStart or searchContinue. |
id |
string | The unique identifier of the search, obtained from |
Returns:
An object containing the batch of results and metadata, including:
- files: an array of File objects representing the matched files
- hasMore: a boolean indicating if more results are available
- path: the path searched
- pattern: the search pattern used
- isRecursive: whether the search was recursive
- batchSize: the size of the batch
- Type
- Object
searchStart(pattern, recursiveopt, batchSizeopt) → {string}
- Description:
Begins a search for files and folders that match a specified pattern within the directory represented by this File object. This method supports recursive searching and batching of results to manage large file systems efficiently.
Example
var searchId = myFolder.searchStart("*.txt", true);
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pattern |
string | The pattern to search for. Supports wildcards ( |
||
recursive |
boolean |
<optional> |
false
|
Whether the search should include subdirectories. |
batchSize |
number |
<optional> |
100
|
The maximum number of results to return in one batch. |
Returns:
A unique identifier for the initiated search. Use this identifier to fetch results with searchContinue and to abort the search with searchAbort.
- Type
- string
testGetFiles() → {Boolean}
- Description:
Test to see if a folder can be listed (without listing all the files).
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.
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.
Returns:
- Type
- String
unzip(destinationFolder, overwrite)
- Description:
Unzip this file to the destination folder.
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.
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.
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.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
String | Text to write to the file. |
Returns:
- Type
- void