繁体   English   中英

Nodejs对目录的非法操作

[英]Nodejs illegal operation on a directory

我正在尝试使用markdown-pdf NPM软件包将markdown文件的文件夹编译为单个PDF。

我有一个简单的脚本来完成这项工作:

var mpdf = require('markdown-pdf');
var fs = require('fs');

var mDocs = fs.readdirSync('./understandinges6/manuscript/');
mDocs = mDocs.map(function(d) { return 'understandinges6/manuscript/' + d });

var Book = 'understandinges6.pdf';

mpdf().concat.from(mDocs).to(Book, function() {
    console.log("Created", Book);
});

但是当我执行脚本时,会出现此错误:

events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: EISDIR: illegal operation on a directory, read
    at Error (native)

这很奇怪,因为我位于具有相应权限的主文件夹中。 我在脚本中指定输出文件夹/文件,然后使用fs.readdirSync读取。

有什么想法吗?

mDocs = mDocs.map(function(d) { return 'understandinges6/manuscript/' + d }); 您忘记添加“ ./”。 重写为mDocs = mDocs.map(function(d) { return './understandinges6/manuscript/' + d });

很酷,我在这里遇到问题:

manuscripts/文件夹中是带有一些png的images/子文件夹。 当脚本尝试将images/.md转换为.pdf.md了错误。

这是图像/内部的数组:

[ 'understandinges6/manuscript/00-Introduction.md',
  'understandinges6/manuscript/01-Block-Bindings.md',
  'understandinges6/manuscript/02-Strings-and-Regular-Expressions.md',
  'understandinges6/manuscript/03-Functions.md',
  'understandinges6/manuscript/04-Objects.md',
  'understandinges6/manuscript/05-Destructuring.md',
  'understandinges6/manuscript/06-Symbols.md',
  'understandinges6/manuscript/07-Sets-And-Maps.md',
  'understandinges6/manuscript/08-Iterators-And-Generators.md',
  'understandinges6/manuscript/09-Classes.md',
  'understandinges6/manuscript/10-Arrays.md',
  'understandinges6/manuscript/11-Promises.md',
  'understandinges6/manuscript/12-Proxies-and-Reflection.md',
  'understandinges6/manuscript/13-Modules.md',
  'understandinges6/manuscript/A-Other-Changes.md',
  'understandinges6/manuscript/B-ECMAScript-7.md',
  'understandinges6/manuscript/Book.txt',
  'understandinges6/manuscript/images' ]

解? 只需pop() mDocs数组(现在只是docs ):

var mpdf = require('markdown-pdf');
var fs = require('fs');

var mDocs = fs.readdirSync('understandinges6/manuscript/');
var docs = mDocs.map(function(d) { return 'understandinges6/manuscript/' + d });

docs.pop();

var Book = 'understandinges6.pdf';

mpdf().concat.from(docs).to(Book, function() {
    console.log("Created", Book);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM