Working with Filepaths
Jaxer is able to handle both filesystem paths and file:/// urls and provides some convenience methods to resolve provided paths to an actual location on the filesystem.
Let's look at how we would convert from an filesystem path to a URL and vice versa
As you can see, these methods provide a simple way to convert from file system paths to file protocol URL's and vice versa.
Jaxer also provides a way to resolve a relative file path into an absolute path:
Using a combination of these methods will generally allow us to manipulate a provided path or Url to the required path we need.
Creating cross platform filepaths
In JavaScript, to include a backslash in a string, you need to use the escaped notation of '\\' or the character following the
backslash is interpreted as an 'escaped' literal. (i.e. 'c:\new folder' appears as if it had a newline between the colon and the 'e').
Jaxer provides a handy tool to deal with this. Use the built in Jaxer.System.separator, which returns the system path separator and is very useful when building paths by concatenation of sub-paths.
This technique for creating paths has the advantage of being cross-platform. For example, in the above snippet, the fact that the path is rooted at 'c:' means that it is actually windows specific.
A cleaner way to do this is provided by the Jaxer.Dir.combine(args) method, which concatenates a list of parts into a full path joined with the platform path separator and cleans any extra path separators contained in the list.
Jaxer provides some convenient properties on the Jaxer.System namepsace to locate important system folders in a cross platform
manner.
The Desktop folder of the user account running Jaxer can be located using the Jaxer.System.desktopFolder, and the home folder
can be located with Jaxer.System.homeFolder
The Folder containing the Jaxer binaries can be located using the Jaxer.System.executableFolder: