Skip to content

Instantly share code, notes, and snippets.

@triacontane
Created October 6, 2016 11:34
Show Gist options
  • Save triacontane/8f15fc1b2da5e8ab39d1077fabaee2a0 to your computer and use it in GitHub Desktop.
Save triacontane/8f15fc1b2da5e8ab39d1077fabaee2a0 to your computer and use it in GitHub Desktop.
プロジェクト内の指定したフォルダ配下の全ファイルに対して処理を実行
var path = require('path');
// base:実行中のプロジェクトのルートパス
var base = path.dirname(process.mainModule.filename);
// filePath:base + img/pictures
var filePath = path.join(base, 'img/pictures/');
var fs = require('fs');
// img/pictures配下のファイルに対して繰り返し処理を実行
fs.readdirSync(filePath).forEach(function(fileName) {
console.log(fileName);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment