nodejs遍历文件夹

var fs = require('mz/fs');
var path = require('path');


async function showFiles(param) {
    var stat = await fs.stat(param);
    if (stat.isDirectory()) {
        var files = await fs.readdir(param);
        files.forEach(e => {
            const absolutePath = path.join(param, e);
            showFiles(absolutePath)
        })
    } else {
        var key = 'web/admin/music_org_admin/' + param.split('dist/')[1];
        var localFile = './' + param;
        console.log(key, localFile);
    }
}
showFiles('./dist')

你可能感兴趣的:(nodejs遍历文件夹)