DevelopmentOpen SourceXRap

Keeping it Cross-Platform

By February 22, 2009August 21st, 2013No Comments

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“);

Leave a Reply