Search code examples
firefoxfirefox-addonmozilla

Firefox Add-on save to desktop


I'm trying to save a file in a folder other than the extensions folder. Right now I'm using:

var file = Components.classes["@mozilla.org/file/directory_service;1"].  
                         getService(Components.interfaces.nsIProperties).  
                         get("ProfD", Components.interfaces.nsIFile);  
    if( !file.exists() || !file.isDirectory() ) {   // if it doesn't exist, create  
       file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);  
    }  

this.f = file.path+"\\text.txt";

How can I change the file path so that it saves it somewhere else on the machine? Or is this not possible?

Thanks!


Solution

  • You can use different "special folder" keys too. For a list of some common ones, see:
    https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO#Getting_special_files

    You can also initialize a file with any absolute path. See:
    https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO#Creating_an_.0ansIFile.0a_object_%28.22opening.22_files%29