简体   繁体   English

Node.JS fs.WriteFile路径作为字符串

[英]Node.JS fs.WriteFile path as a string

I am trying to save a simple file to a directory other then my root directory, but it seems to error out when using a variable instead of a direct string.Has anyone tried using a variable or see if i am missing something. 我正在尝试将一个简单的文件保存到我的根目录以外的其他目录中,但是使用变量而不是直接字符串时似乎出错了。有人尝试使用变量还是看看我是否缺少某些东西。 Thanks 谢谢

var procedures = "SomeString";
var moveTo = "C:/SavedFiles";
//////////////////
fs.writeFile(moveTo ,procedures, function (err) {
            if (err) {
                return console.log(err);
            }
            console.log("The file was saved!");
        });`

Am I correct that "C:/SavedFiles" is a directory? 我是否正确认为“ C:/ SavedFiles”是目录? Is so, then specify a file to write to like: 是这样,然后指定要写入的文件:

var moveTo = "C:/SavedFiles/myfile.txt";
// keep the rest the same

Not sure about the slashes though, not running Windows ATM. 虽然不确定斜杠,但未运行Windows ATM。

So it looks like my error was due to a rouge loop above my code not posted. 所以看来我的错误是由于我的代码上方的红色循环没有发布。 Sorry i didn't post the rest of the code 抱歉,我没有发布其余代码

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

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