var fs= require('fs');
var epubZip= require('epub-zip');
var content = epubZip('./tests/epubs/epub1');
var content2= epubZip('./tests/epubs/epub2');
fs.writeFileSync("./tests/dist/epub1.epub",content);
fs.writeFileSync("./tests/dist/epub2.epub",content2);
例如,这是用于生成2个epub文件的代码,如何只通过编写一个fs.writeFileSync函数来自动获取多个输出。
答案 0 :(得分:0)
function getDirectories(mypath) {
return fs.readdirSync(mypath).filter(function(file) {
if(fs.statSync(path.join(mypath, file)).isDirectory()) {
//console.log('mypath is :',file);
var newpath = mypath+'/'+file;
//console.log('newpath is:'+newpath);
var content =epubZip(newpath);
var writepath=mywritepath+'/'+file+'.epub';
//console.log('writepath is:'+writepath);
fs.writeFileSync(writepath,content);
}
这就是我修复问题的方法,将我的目录名称附加到路径