Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9324

Node.jsを利用してフォルダ作成を効率化してみる

$
0
0

はじめに

「001」「002」「003」・・・「100」のような大量のフォルダを作成する必要があり、手作業でやるのは馬鹿馬鹿しいのでNode.jsで作ってみました。Windowsで動作します。

mkdir.js
constfs=require('fs')// プログラム実行ディレクトリ配下を指定constrootPath=process.cwd()+'\\';for(leti=1;i<=100;i++){constnum=('000'+i).slice(-3);constdirectoryPath=rootPath+num;fs.stat(directoryPath,(error,stats)=>{if(error){if(error.code==='ENOENT'){fs.mkdir(directoryPath,(error)=>{if(error){throwerror}else{console.log(`${directoryPath}ディレクトリを作成できました。`)}});}else{console.log(error);}}else{console.log(`${directoryPath}ディレクトリは既に存在します。`);}})}

Viewing all articles
Browse latest Browse all 9324

Trending Articles