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

Leave a Reply

Your email address will not be published. Required fields are marked *