Node.js错误ENOENT,打开“文件/路径"当什么都没有改变时 [英] Node.js Error ENOENT, open "file/path" when nothing has been changed

查看:140
本文介绍了Node.js错误ENOENT,打开“文件/路径"当什么都没有改变时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,首先...我是Node.js的新手.我正在尝试将Word文档转换为HTML,然后将其抓取以获得内容.然后将其泵入现有发动机中.

Ok first off... I'm new to Node.js. I'm trying to convert a word document to HTML then scrapping it to obtain the content. Then pump it into an existing engine.

话虽这么说,直到今天一切都还算顺利.昨晚我刚开始运行fs.writeFile并离开了它.今天早晨,我没有碰它并尝试运行它,我收到了这个消息:

With that being said, everything was running fairly smoothly until today. I just got the fs.writeFile working last night and stepped away from it. This morning without touching it and trying to run it I receive this:

这是调用错误的块.

//COPY TEMPLATE AND PASTE
fs.readFile("./Templates/TextBasedEvent.xml", function (err, data){
    if (err) {
        throw err;
    }       
    var contentHolder = data.toString(),            
        contentHolder = contentHolder.replace(/%EVENTNUMBER%/gi, id),
        contentHolder = contentHolder.replace(/%CONTENT%/gi, contents);
    fs.writeFile("./bin/xml/" + id + ".xml", contentHolder, function (err){
        if (err) {
            throw err;
        }
    });
});

与变量在文件路径中的放置方式有关系吗?同样,对于它,在该变量所在的位置之间软返回它似乎很奇怪,因此抛出err似乎很奇怪.

Does it have something to do with how the variable is placed in the file path? also the throw err for it just seems weird that it soft returned in between where the variable is.

谢谢!

问题在于换行符与变量一起插入.

The issue was with newline being pulled in, with the variable.

推荐答案

在写入文件时,有几件事可能会导致ENOENT.

There are a few things that might cause ENOENT when writing a file.

  • 目标目录(在本例中为E:\Desktop\SniffIt\bin\xml)不存在.
  • 文件名中的换行符(CR和/或LF).
  • The destination directory (in this case, E:\Desktop\SniffIt\bin\xml) does not exist.
  • A newline (CR and/or LF) in the filename.

您应该使用正确的XML解析器来读取输入文件.这可能会帮助您避免出现虚假的换行符.

You should be using a proper XML parser to read your input file. This would probably help you avoid the spurious newlines you're getting.

这篇关于Node.js错误ENOENT,打开“文件/路径"当什么都没有改变时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆