The JSFile is an IScriptObject representation of a file, supporting local, remote, and web contexts. It provides functionalities to manipulate files, such as checking read/write permissions, creating or deleting files, and managing file properties like size, type, and last modified date. Operations on directories are also supported, allowing directory creation and listing of contents.
Methods Summarized
Type
Name
Summary
Returns true if the file exists and is readable (has access to it) - works on remote files too.
Returns true if the file exists and can be modified - works on remote files too.
Return a new JSFile instance that contains a remote file with the content of current JSFile.
Creates the file on disk if needed.
Deletes the file from the disk if possible.
Returns true if the file/directory exists on the filesystem - works on remote files too.
Returns a JSFile instance that corresponds to the absolute form of this pathname - works on remote files too.
Returns a String representation of the absolute form of this pathname - works on remote files too.
Gets the contents (bytes) for the file data.
Returns the contenttype of this file, like for example 'application/pdf' - works on remote files too.
Returns the name of the file.
Returns the String representation of the path of the parent of this file - works on remote files too.
Returns a JSFile instance that corresponds to the parent of this file - works on remote files too.
Returns a String holding the path to the file - works on remote files too.
Get a url from file that can be used to download the file in a browser.
Returns true if the path is absolute.
Returns true if the file is a directory - works on remote files too.
Returns true if the file is a file and not a regular file - works on remote files too.
Returns true if the file is hidden (a file system attribute) - works on remote files too.
Returns the time/date of the last modification on the file - works on remote files too.
Returns an array of strings naming the files and directories located inside the file, if the file is a directory - works on remote files too.
Returns an array of JSFiles naming the files and directories located inside the file, if the file is a directory - works on remote files too.
Creates a directory on disk if possible.
Creates a directory on disk, together with all its parent directories, if possible.
Renames the file to a different name.
Set the content of the file (local or remote) to the bytes provided Will not create a new file if one doesn't exist
Set the content of the file (local or remote) to the bytes provided
Sets the date/time of the last modification on the file.
Sets the readonly attribute of the file/directory.
Returns the size in bytes of the file.
Methods Detailed
canRead()
Returns true if the file exists and is readable (has access to it) - works on remote files too.
var f =plugins.file.convertToJSFile('./big.jpg');// or for a remote file:// var f = plugins.convertToRemoteJSFile('/images/big.jpg');if (f &&f.exists()) {application.output('is absolute: '+f.isAbsolute());application.output('is dir: '+f.isDirectory());application.output('is file: '+f.isFile());application.output('is hidden: '+f.isHidden());application.output('can read: '+f.canRead());application.output('can write: '+f.canWrite());application.output('last modified: '+f.lastModified());application.output('name: '+f.getName());application.output('path: '+f.getPath());application.output('absolute path: '+f.getAbsolutePath());application.output('content type: '+f.getContentType());application.output('size: '+f.size());}else {application.output('File/folder not found.');}
canWrite()
Returns true if the file exists and can be modified - works on remote files too.
var f =plugins.file.convertToJSFile('./big.jpg');// or for a remote file:// var f = plugins.convertToRemoteJSFile('/images/big.jpg');if (f &&f.exists()) {application.output('is absolute: '+f.isAbsolute());application.output('is dir: '+f.isDirectory());application.output('is file: '+f.isFile());application.output('is hidden: '+f.isHidden());application.output('can read: '+f.canRead());application.output('can write: '+f.canWrite());application.output('last modified: '+f.lastModified());application.output('name: '+f.getName());application.output('path: '+f.getPath());application.output('absolute path: '+f.getAbsolutePath());application.output('content type: '+f.getContentType());application.output('size: '+f.size());}else {application.output('File/folder not found.');}
convertToRemote(fileName)
Return a new JSFile instance that contains a remote file with the content of current JSFile.
Creates the file on disk if needed. Returns true if the file (name) did not already exists and had to be created - for remote, use the streamFilesToServer to stream a file.
var f =plugins.file.convertToJSFile('story.txt');if (!f.exists())f.createNewFile();
deleteFile()
Deletes the file from the disk if possible. Returns true if the file could be deleted. If the file is a directory, then it must be empty in order to be deleted - works on remote files too.
var f =plugins.file.convertToJSFile('story.txt');// or for a remote file:// var f = plugins.convertToRemoteJSFile('/story.txt');if (f &&f.exists())f.deleteFile();
exists()
Returns true if the file/directory exists on the filesystem - works on remote files too.
var f =plugins.file.convertToJSFile('./big.jpg');// or for a remote file:// var f = plugins.convertToRemoteJSFile('/images/big.jpg');if (f &&f.exists()) {application.output('is absolute: '+f.isAbsolute());application.output('is dir: '+f.isDirectory());application.output('is file: '+f.isFile());application.output('is hidden: '+f.isHidden());application.output('can read: '+f.canRead());application.output('can write: '+f.canWrite());application.output('last modified: '+f.lastModified());application.output('name: '+f.getName());application.output('path: '+f.getPath());application.output('absolute path: '+f.getAbsolutePath());application.output('content type: '+f.getContentType());application.output('size: '+f.size());}else {application.output('File/folder not found.');}
getAbsoluteFile()
Returns a JSFile instance that corresponds to the absolute form of this pathname - works on remote files too.
var f =plugins.file.convertToJSFile('story.txt');// or for a remote file:// var f = plugins.file.convertToRemoteJSFile('/story.txt');application.output('parent folder: '+f.getAbsoluteFile().getParent());application.output('parent folder has '+f.getAbsoluteFile().getParentFile().listFiles().length+' entries');
getAbsolutePath()
Returns a String representation of the absolute form of this pathname - works on remote files too.
var f =plugins.file.convertToJSFile('./big.jpg');// or for a remote file:// var f = plugins.convertToRemoteJSFile('/images/big.jpg');if (f &&f.exists()) {application.output('is absolute: '+f.isAbsolute());application.output('is dir: '+f.isDirectory());application.output('is file: '+f.isFile());application.output('is hidden: '+f.isHidden());application.output('can read: '+f.canRead());application.output('can write: '+f.canWrite());application.output('last modified: '+f.lastModified());application.output('name: '+f.getName());application.output('path: '+f.getPath());application.output('absolute path: '+f.getAbsolutePath());application.output('content type: '+f.getContentType());application.output('size: '+f.size());}else {application.output('File/folder not found.');}
var f =plugins.file.convertToJSFile('./big.jpg');// or for a remote file:// var f = plugins.convertToRemoteJSFile('/images/big.jpg');if (f &&f.exists()) {application.output('is absolute: '+f.isAbsolute());application.output('is dir: '+f.isDirectory());application.output('is file: '+f.isFile());application.output('is hidden: '+f.isHidden());application.output('can read: '+f.canRead());application.output('can write: '+f.canWrite());application.output('last modified: '+f.lastModified());application.output('name: '+f.getName());application.output('path: '+f.getPath());application.output('absolute path: '+f.getAbsolutePath());application.output('content type: '+f.getContentType());application.output('size: '+f.size());}else {application.output('File/folder not found.');}
getName()
Returns the name of the file. The name consists in the last part of the file path - works on remote files too.
var f =plugins.file.convertToJSFile('./big.jpg');// or for a remote file:// var f = plugins.convertToRemoteJSFile('/images/big.jpg');if (f &&f.exists()) {application.output('is absolute: '+f.isAbsolute());application.output('is dir: '+f.isDirectory());application.output('is file: '+f.isFile());application.output('is hidden: '+f.isHidden());application.output('can read: '+f.canRead());