node.js fs.readdir recursive directory search

前端 未结 30 1528
醉酒成梦
醉酒成梦 2020-11-22 15:55

Any ideas on an async directory search using fs.readdir? I realise that we could introduce recursion and call the read directory function with the next directory to read, bu

30条回答
  •  伪装坚强ぢ
    2020-11-22 16:11

    If you want to use an npm package, wrench is pretty good.

    var wrench = require("wrench");
    
    var files = wrench.readdirSyncRecursive("directory");
    
    wrench.readdirRecursive("directory", function (error, files) {
        // live your dreams
    });
    

    EDIT (2018):
    Anyone reading through in recent time: The author deprecated this package in 2015:

    wrench.js is deprecated, and hasn't been updated in quite some time. I heavily recommend using fs-extra to do any extra filesystem operations.

提交回复
热议问题