0

如何以编程方式创建新目录/文件夹?我正在下载 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');
4

2 回答 2

2

导入OS.File 模块并使用makeDir

于 2013-08-04T12:50:14.333 回答
1

此外,SDK 还提供文件实用程序,例如 mkpath (mkdir -p)

我相信在 FF25 中(目前在 Nightly 中),该io/fs模块将变得可用,它与node 的 fs 模块具有同等地位

于 2013-08-04T17:57:04.717 回答