jsÔõô½¨ÉèÎļþ¼Ð
ʹÓà js ½¨ÉèÎļþ¼ÐÐèÒªµÚÈý·½¿â»ò node.js µÄ fs Ä£¿é£¬ÏêϸҪÁìÈçÏ£ºµÚÈý·½¿â£ºjs-file-manager£ºÒ»¸öÇáÁ¿¼¶µÄ¿â£¬Ìṩ½¨ÉèÎļþ¼Ð¡¢¶ÁÈ¡¡¢Ð´ÈëÎļþµÈ¹¦Ð§¡£fs-extra£ºÀ©Õ¹ÁË node.js ÔÉú fs Ä£¿é£¬Ìí¼ÓÁ˽¨ÉèÎļþ¼ÐµÈ¹¦Ð§¡£node.js fs Ä£¿é£ºfs.mkdir(path)£ºÓÃÓÚ½¨ÉèÎļþ¼Ð¡£ÈôÊÇÎļþ¼Ð²»±£´æ£¬Ôò»á½¨ÉèËü¡£ÈôÊÇÎļþ¼ÐÒѱ£´æ£¬Ôò²»»áÖ´ÐÐÈκβÙ×÷¡£fs.mkdirsync(path)£ºfs.mkdir µÄͬ²½°æ±¾¡£Ëü»áÅ׳öÒì³££¬ÈôÊÇÎļþ¼ÐÒÑ
ÔõÑùʹÓà JS ½¨ÉèÎļþ¼Ð
Ö±½Ó»Ø¸²£º
ʹÓà JS ½¨ÉèÎļþ¼Ð£¬ÐèÒª½èÖúµÚÈý·½¿â»ò Node.js µÄ fs Ä£¿é¡£
ÏêϸÕö¿ª£º
µÚÈý·½¿â£º
js-file-manager£ºÒ»¸öÇáÁ¿¼¶µÄ¿â£¬Ìṩ½¨ÉèÎļþ¼Ð¡¢¶ÁÈ¡¡¢Ð´ÈëÎļþµÈ¹¦Ð§¡£
fs-extra£ºÀ©Õ¹ÁË Node.js ÔÉú fs Ä£¿é£¬Ìí¼ÓÁ˽¨ÉèÎļþ¼ÐµÈ¹¦Ð§¡£
Node.js fs Ä£¿é£º
fs.mkdir(path)£ºÓÃÓÚ½¨ÉèÎļþ¼Ð¡£ÈôÊÇÎļþ¼Ð²»±£´æ£¬Ôò»á½¨ÉèËü¡£ÈôÊÇÎļþ¼ÐÒѱ£´æ£¬Ôò²»»áÖ´ÐÐÈκβÙ×÷¡£
fs.mkdirSync(path)£ºfs.mkdir µÄͬ²½°æ±¾¡£Ëü»áÅ׳öÒì³££¬ÈôÊÇÎļþ¼ÐÒѱ£´æ¡£
ʾÀý£º
ʹÓà js-file-manager£º
const fileManager = require('js-file-manager'); fileManager.mkdir('my-folder');
µÇ¼ºó¸´ÖÆ
ʹÓà fs-extra£º
const fs = require('fs-extra'); fs.mkdir('my-folder');
µÇ¼ºó¸´ÖÆ
ʹÓà fs Ä£¿é£º
const fs = require('fs'); fs.mkdir('my-folder', (err) => { if (err) { // ÍÉ»¯´¦Àí } });
µÇ¼ºó¸´ÖÆ
ͬ²½°æ±¾£º
fs.mkdirSync('my-folder');
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇjsÔõô½¨ÉèÎļþ¼ÐµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡