Last active
May 31, 2016 18:06
-
-
Save yuryshulaev/3ec50bf6b1b4331ac9d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// babel countfiles_es7.js -o countfiles_es7.out.js --optional runtime --source-maps inline | |
require('source-map-support').install(); | |
import Promise from 'bluebird'; | |
import path from 'path'; | |
let fs = Promise.promisifyAll(require('fs')); | |
class FileCounter { | |
static async countFiles(dir) { | |
let files = await fs.readdirAsync(dir); | |
let paths = files.map(file => path.join(dir, file)); | |
let stats = await* paths.map(path => fs.statAsync(path)); | |
return stats.filter(stat => stat.isFile()).length; | |
} | |
} | |
(async function () { | |
try { | |
let num = await FileCounter.countFiles(__dirname); | |
console.log('There are ' + num + ' files in ' + __dirname); | |
} catch (err) { | |
console.error(err); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment