Open Source / XRap

Keeping it Cross-Platform

By using the nsIFilePicker you can get the absolute path to your destination according to the platform you are working on.  The most basic problem in navigating between Windows and Linux is the direction of the slash which separates the directories in the path.

Path on Linux

Path on Linux

Path on Windows

Path on Windows

By using the nsIFilePicker you can avoid having to deal with what platform you are working on.  However, if you want to start manipulating files or subdirectories, then you must attach the nsIFile interface to your path, and use the append() function to add to the path. 

var appRootDir= Components.classes[“@mozilla.org/file/local;1”]
          .createInstance(Components.interfaces.nsILocalFile);
appRootDir.initWithPath(applicationPath);
appRootDir.append(“DirectoryName“);
appRootDir.append(“FileName.txt“);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s