nodeschool learnyounode node.js module FILTER LS exercise

后端 未结 8 1300
面向向阳花
面向向阳花 2021-02-10 05:38

Below is the exercise 5 of nodeschool learnyounode module

Create a program that prints a list of files in a given directory, filtered by he extension of the files. You w

8条回答
  •  礼貌的吻别
    2021-02-10 06:11

    Here's the official solution:

    var fs = require('fs')
    var path = require('path')
    
    fs.readdir(process.argv[2], function (err, list) {
      list.forEach(function (file) {
        if (path.extname(file) === '.' + process.argv[3])
          console.log(file)
      })
    })
    

提交回复
热议问题