127
119

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.js ファイル一覧を取得する

Last updated at Posted at 2013-09-10

メモ。
以下は、カレントディレクトリから拡張子csvのファイル一覧を取得するスニペット

var fs = require('fs');
fs.readdir('.', function(err, files){
	if (err) throw err;
	var fileList = [];
	files.filter(function(file){
		return fs.statSync(file).isFile() && /.*\.csv$/.test(file); //絞り込み
	}).forEach(function (file) {
		fileList.push(file);
	});
	console.log(fileList);
});

コメント欄にて教えてもらった方法で再掲。

var fs = require('fs');
fs.readdir('.', function(err, files){
	if (err) throw err;
	var fileList = files.filter(function(file){
		return fs.statSync(file).isFile() && /.*\.csv$/.test(file); //絞り込み
	})
	console.log(fileList);
});
127
119
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
127
119

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?