Saturday, July 28, 2007

Javascript get the local file path in Mozilla

This function gives you the local file path of the file (nsIFile).

function getLocalFilePath(file) {
// file is nsIFile
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var fileHandler = ios.getProtocolHandler("file")
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
var URL = fileHandler.getURLSpecFromFile(file);
return URL;
}

No comments: