查看“︁Node.js/fs”︁的源代码
来自康健生活
←
Node.js/fs
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 标题文字 == == 写入 == == 批量生成文件 == {{Hc|create.js|<syntaxhighlight lang="javascript"> const fs = require('fs'); const path = require('path'); function generator(count,filename,suffix) { count = parseInt(count); const length = count.toString().length; const htmlDoc= `<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> </body> </html>`; const jsDoc=`'use stict';const foo = `; const content=suffix=='js'?jsDoc:htmlDoc; for (let i = 1; i < count + 1; i++) { let relativename=`${filename+i.toString() }.`+suffix; let fullname=path.join(__dirname, relativename); fs.stat(fullname,function(err,stat){ if(!(stat && stat.isFile())){ fs.writeFile(fullname, content + i, ()=>{console.log(i)}); } }); } } const init = (args) => { const count = args[0]; const filename=args[1] || 'index'; const suffix=args[2] || 'html'; if (count) { generator(count, filename, suffix); } else { const readline = require('readline'); const rl = readline.createInterface(process.stdin, process.stdout); rl.question('生成几个代码文件?', (c) => { generator(c,filename,suffix); rl.close(); }); } }; init([process.argv[2], process.argv[3], process.argv[4]]); </syntaxhighlight>}} 生成文件。 {{shc|<syntaxhighlight lang="bash"> node create.js 200 testfile_ js</syntaxhighlight>|$|/home/kangkk}}
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
模板:Shc
(
查看源代码
)
模板:Shc/style.css
(
查看源代码
)
模板:Version
(
查看源代码
)
模板:Version/style.css
(
查看源代码
)
返回
Node.js/fs
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。