如何以编程方式创建新目录/文件夹?我正在下载 mp3 并保存它们,但我想按流派 (newDirectoryName) 将它们分开。到目前为止,这是我的代码..
function DownloadFile(sLocalFileName, newDirectoryName, sRemoteFileName)
{
var saveToDirectory = 'C:\\Users\\louis\\downloads\\'+newDirectoryName+'\\';
console.log("downloading : "+saveToDirectory);
var chrome = require("chrome");
var oIOService = chrome.Cc["@mozilla.org/network/io-service;1"].getService(chrome.Ci.nsIIOService)
var oLocalFile = chrome.Cc["@mozilla.org/file/local;1"].createInstance(chrome.Ci.nsILocalFile);
oLocalFile.initWithPath(saveToDirectory + sLocalFileName);
var oDownloadObserver = {onDownloadComplete: function(nsIDownloader, nsresult, oFile) {console.log('download complete...')}};
var oDownloader = chrome.Cc["@mozilla.org/network/downloader;1"].createInstance();
oDownloader.QueryInterface(chrome.Ci.nsIDownloader);
oDownloader.init(oDownloadObserver, oLocalFile);
var oHttpChannel = oIOService.newChannel(sRemoteFileName, "", null);
oHttpChannel.QueryInterface(chrome.Ci.nsIHttpChannel);
oHttpChannel.asyncOpen(oDownloader, oLocalFile);
console.log("should be downloading!!!!");
}
DownloadFile('filename.mp3','genre','http://domain.com/file.mp3');