Initial learning Nodejs, amateur use node to write a small script that automatically creates directories and files, hoping to help people in need

Source: Internet
Author: User

Preliminary study Nodejs, amateur with node write a small script to automatically create directories and files, want to be helpful to those who need, if there are bugs or better optimization, please criticize and correct, thank you, the code is as follows:

1 varFS = require (' FS ');2 varTel = [3"1/2/4/6/a.tpl.html",4"1/2/4/7/9/c.tpl.html",5"1/3/5/8/b.tpl.html"];6 varDemo =function(Mulu) {7     varMuluatr = Mulu.split ("/");8Muluatr.foreach (function(value, i) {9i++;Ten         if(i = =muluatr.length) { One             if(!! Value.match (/\./g)) { A                 if(!!Fs.existssync (Mulu)) { -                     returnConsole.log ("File:" + Mulu + "already exists"); -}Else{ the                     if(Fs.opensync (Mulu, ' wx+ '))){ -                         returnConsole.log ("File:" + Mulu + "Create successful"); -}Else{ -                         returnConsole.log ("File:" + Mulu + "Create failed"); +                     } -                 } +             } A         } at         varMunstr = Muluatr.slice (0, I). Join ("/"); -         if(!!Fs.existssync (MUNSTR)) { -             returnConsole.log ("directory:" + Munstr + "already exists"); -}Else{ -             if(!Fs.mkdirsync (MUNSTR)) { -                 returnConsole.log ("directory:" + MUNSTR + "Create successful"); in}Else{ -                 returnConsole.log ("directory:" + munstr + "Create failed"); to             } +         } -     }); the }; *Tel.foreach (function(value,i) {demo (value);});

As for the folders and files you want to create in an array form and assign to the Tel variable, the directory is relative to the directory where your script files are located.

Initial learning Nodejs, amateur use node to write a small script that automatically creates directories and files, hoping to help people in need

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.