| Written by Arash Karimzadeh | 
        
          | Sunday, 28 June 2009 06:01 | 
        
          | Here we will see how we can access a specific directory in XUL application by javascript. There is a service provided by mozilla called "@mozilla.org/file/directory_service". by using following code you can access the location of Profile Directory of your computer:   
              
              
                
                  
                    var file = Components.classes["@mozilla.org/file/directory_service;1"]
                  
                  
                                         .getService(Components.interfaces.nsIProperties)
                  
                  
                                         .get("ProfD", Components.interfaces.nsIFile);
                   
                var%20file%20%3D%20Components.classes%5B%22%40mozilla.org%2Ffile%2Fdirectory_service%3B1%22%5D%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20.getService%28Components.interfaces.nsIProperties%29%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20.get%28%22ProfD%22%2C%20Components.interfaces.nsIFile%29%3B
               The "ProfD" means Profile Directory.
 
 You can replace it with other options such as:
 
              
                
                  | Desk 
 | Desktop directory (e.g. ~/Desktop on Linux, C:\Documents and Settings\username\Desktop on Windows) 
 |  
                  | AChrom | %installation%/chrome  (e.g. myApp/chrome/) 
 |  
                  | UChrm 
 | %profile%/chrome 
 |  
                  | ProfD 
 | profile directory 
 |  
                  | DefProfRt 
 | user |  
                  | DefRt 
 | %installation%/defaults (e.g. myApp/defaults/) |  
                  | PrfDef | %installation%/defaults/pref (e.g. myApp/xulrunner/defaults/pref) |  
                  | ProfDefNoLoc | %installation%/defaults/profile (e.g. myApp/xulrunner/defaults/profile) |  
                  | APlugns | %installation%/plugins |  
                  | ComsD | %installation%/components |  
                  | CurProcD | installation (usually) |  
                  | Home | OS root (e.g., C:\Documents and Settings\username on Windows or /root on Linux) |  
                  | TmpD | OS tmp (e.g., /tmp) |  
                  | ProfLD | Local Settings on windows; where the network cache and fastload files are stored |  
                  | resource:app | application directory in a XULRunner app |  
                  | Progs | User start menu programs directory (e.g., C:\Documents and Settings\username\Start Menu\Programs) |   *The above examples are for an application called myApp. You can create this project by reading this article. You can find more other options at xpcom/io/nsAppDirectoryServiceDefs.h and xpcom/io/nsDirectoryServiceDefs.h. Tags: Chrome | JavaScript | xul | 
        
          | Last Updated on Sunday, 28 June 2009 09:18 |