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.



Aptana Jaxer 0.9 Beta Release Documentation

Simple File Access

Jaxer provides a number of simple methods for easy access to files on the filesystem, this section provides an overview of those.

Create a file

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:

Truncate a file

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:

Delete a file

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:

Check if a file exists.

To check is a file exists, use the Jaxer.File.exists(path) static method:

Get the size of a file

To get the size of file, the Jaxer.File.size(path) method is available. This will return the size of the file in bytes:

Extract the filename from a filepath

To extract the filename from a filepath, the Jaxer.File.filename(path) method is available. This will return the filename portion of the path:

Extract the extension from a filepath

To extract the extension from a filepath, the Jaxer.File.extension(path) method is available. This will return the extension portion of the path:

Extract the absolute filesystem path from a filepath

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:

Extract the path of the containing folder from a filepath

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:

Get the last modified date of a file

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:

Get/Set file access permissions

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.

Calculate the CRC32 checksum of a file

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:

Retrieve the contents of a file.

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:

Append to file

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 contents
line1line2

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 contents
line1
line2

Copy a file

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.

Move a file

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.

Backup a file

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: