find file with wild card matching

后端 未结 5 1694
滥情空心
滥情空心 2020-12-08 18:31

In node.js, can I list files with wild card matching like

fs.readdirSync(\'C:/tmp/*.csv\')?

I did not find the information on wild card ma

5条回答
  •  一整个雨季
    2020-12-08 18:36

    If you don't want to add a new dependency to your project (like glob), you can use plain js/node functions, like:

    var files = fs.readdirSync('C:/tmp').filter(fn => fn.endsWith('.csv'));
    

    Regex may help in more complex comparisons

提交回复
热议问题