Chapters
Other Resources
- Jaxer FAQ
Still have questions? - Jaxer API Docs
Browse through our online API documentation.
| Jaxer Update Available. |
Jaxer 1.0 RC B is now available at the Download Page. This release has many new features and updated APIs. Jaxer 1.0 RC B API docs: Available inside Aptana Studio after you run the update. Additional Info: Jaxer 0.9 Beta to Jaxer 1.0 RC Migration Guide. |
Jaxer provides a number of simple methods for easy access to files on the filesystem, this section provides an overview of those.
We can create a file simply by using the Jaxer.File.touch(path) static method. This will create this file if it doesn't exist and set the last modified timestamp if it does:
If you need to empty the contents of a file, the Jaxer.File.truncate(path) method is available. This will empty the file of its current contents:
To delete a file, the Jaxer.File.remove(path) method is available. This will delete the file from the filesystem. Care should be taken as this is a destructive operation:
To check is a file exists, use the Jaxer.File.exists(path) static method:
To get the size of file, the Jaxer.File.size(path) method is available. This will return the size of the file in bytes:
To extract the filename from a filepath, the Jaxer.File.filename(path) method is available. This will return the filename portion of the path:
To extract the extension from a filepath, the Jaxer.File.extension(path) method is available. This will return the extension portion of the path:
To get the absolute filesystem path from a filepath, the Jaxer.File.absolutePath(path) method is available. This will return the absolute path to the file referenced by the provided path:
To get the absolute filesystem path from a filepath, the Jaxer.File.parentPath(path) method is available. This will return the path to the folder containing the file referenced by the provided filepath:
To get the last modified date from a filepath, the Jaxer.File.dateModified(path) method is available. This will return last modifed date of the file referenced by the provided filepath:
To set the permissions of a file, the Jaxer.File.chmod(path,permissions) method is available. This will set the permissions of the file to the provided value.
To get the permissions of a file we again use Jaxer.File.chmod(path) method, but this time without the optional permissions parameter. This will return the permissions of the file:
The permission value provided/returned is an octal number, in javascript this is a numeric literal with a leading 0.
To get the CRC32 checksum from a filepath, the Jaxer.File.checksum(path) method is available. This will return the CRC32 checksum of the file referenced by the provided filepath:
Once we know that the file exists, we can use the Jaxer.File.read(path) static method to read the entire contents of the file into a javascript variable:
We can add content to an existing file using the Jaxer.File.append(path,content, ...) method. This will add the content to the end of the file. If the file doesn't exist it will be automatically created.
Assuming the file was previously empty or did not exist, the code above would create the file myfile.txt with the contentsline1line2
As an alternative to the Jaxer.File.appendLine(path,content, ...) method, we also have available the Jaxer.File.appendLine() method which will add content to the file but automatically append a new line terminator:
Assuming the file was previously empty or did not exist, the code above would create the file myfile.txt with the contentsline1 line2
To copy a file, the Jaxer.File.copy(source,destination) method is available. This will copy the file to a new location, and the original file remains untouched. Be careful; this is a destructive operation in that it will overwrite the destination file if it exists.
To move a file the Jaxer.File.move(source,destination) method is available, this will move the file to a new location. The original file will be deleted. Be careful; this is a destructive operation in that it will overwrite the destination file if it exists.
To backup a file, the Jaxer.File.backup(path) method is available. This creates a uniquely named copy of the original file. The return value of the method is path to the newly created copy: