gpt4 book ai didi

node.js - Nodejs如何创建包含同名文件的目录

转载 作者:太空宇宙 更新时间:2023-11-04 03:08:31 25 4
gpt4 key购买 nike

我正在使用fs-extra Node 包来创建文件夹和文件,但文件不在正确的路径中,它们最终与文件夹位于同一级别,我需要每个文件都包含在新创建的文件夹中。

fs.mkdirs(filenames[i], function (err) {

if (!err){
fs.writeFile( './'+filenames[i]+'.html', 'hello world' , function( error ){
console.log(error);

});
}

});

最佳答案

我想这可能就是你想要的:

fs.mkdirs(filenames[i], function (err) {

if (!err){
fs.writeFile(filenames[i]+'/'+filenames[i]+'.html', 'hello world' , function( error ){
console.log(error);

});
}

});

关于node.js - Nodejs如何创建包含同名文件的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31766324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com