find file with wild card matching

后端 未结 5 1702
滥情空心
滥情空心 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:32

    If glob is not quite what you want, or a little confusing, there is also glob-fs. The documentation covers many usage scenarios with examples.

    // sync 
    var files = glob.readdirSync('*.js', {});
    
    // async 
    glob.readdir('*.js', function(err, files) {
      console.log(files);
    });
    
    // stream 
    glob.readdirStream('*.js', {})
      .on('data', function(file) {
        console.log(file);
      });
    
    // promise 
    glob.readdirPromise('*.js')
      .then(function(files) {
        console.log(file);
      });
    

提交回复
热议问题