简体   繁体   English

如何在当前工作目录中为Atom软件包创建新文件?

[英]How do i create a new file in the current working directory for an atom package?

I'm trying to make an atom package with JavaScript that will create a new file in the current working directory and add some text to the file. 我正在尝试使用JavaScript制作一个atom包,该包将在当前工作目录中创建一个新文件,并向该文件中添加一些文本。 How would I go about that? 我将如何处理?

So I looked through some other atom packages and found out they use a module called fs and to get the current working directory they use atom.project.getPaths()[0] so I got it to work! 因此,我浏览了其他一些atom软件包,发现它们使用了一个名为fs的模块,并使用atom.project.getPaths()[0]来获取当前的工作目录,所以我开始使用它了!

var fs = require('fs');
fs.writeFile(atom.project.getPaths()[0] + '\\test.txt', "Hey there!", function(err) {
  if(err) {
    return console.log(err);
  }
  console.log("The file was saved!");
});

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

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