title: Anyone know how to proper use the nsIFilePicker ?
body: <p>I am trying to copy a text file from one folder to another. Issue is once you select the folder to save to what is the proper code to get the file to copy to that folder?  I and using NSI Filepicker modeOpen and modeSave and can't find any code on how to save file properly. the MDN is lacking code. </p>
  
  <pre><code>     var dispdir = Components.classes["@mozilla.org/file/directory_service;1"].
       getService(Components.interfaces.nsIProperties).
       get("ProfD", Components.interfaces.nsIFile);    
  
  
       var nsIFilePicker = Components.interfaces.nsIFilePicker;
       var fp = Components.classes["@mozilla.org/filepicker;1"]
      .createInstance(nsIFilePicker);
       fp.init(window, "Select a File", nsIFilePicker.modeOpen);
       fp.appendFilters(nsIFilePicker.filterText);
       fp.displayDirectory = dispdir;
  
  
       var rv = fp.show();
       if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnCancel) {
         var file = fp.file;
         var path = fp.file.path;
  
       }  
  
  
       var savedir = Components.classes["@mozilla.org/file/directory_service;1"].
       getService(Components.interfaces.nsIProperties).
       get("ProfD", Components.interfaces.nsIFile);    
       savedir.append("Test Folder");
  
  
       if( !savedir.exists() || !savedir.isDirectory() ) {   
            // if  it doesn't exist,create
          savedir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
          alert(savedir.path + "\n" + "Folder was made");
  
       }
  
  
       var fp2 = Components.classes["@mozilla.org/filepicker;1"]
            .createInstance(nsIFilePicker);
       fp2.init(window, "Save file to?", nsIFilePicker.modeSave);
       fp2.appendFilters(nsIFilePicker.filterText);
       fp2.displayDirectory = savedir;
       fp2.defaultString = fp.file.leafName; 
  
       var rv = fp2.show();
       if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
  
  
       } 
  
       var aDir = Components.classes["@mozilla.org/file/local;1"]
           .createInstance(Components.interfaces.nsILocalFile);
       aDir.append(fp2.file.parent.path);    
  
  
  
       alert(fp2.file.parent.path)
       fp.file.copyTo(aDir, null);
  
       copyFile(fp.file.path);
       alert(fp2.file.path + "\n" + "File copied successfuly!")       
  </code></pre>