How to get the first file with a .txt extension in a directory with nodejs?

后端 未结 5 1032
感动是毒
感动是毒 2021-02-20 14:06

The directory all my files are in is: \'/usr/home/jordan\' and I have many files under there (in the directory itself, but one file that is named with a .txt extension.

5条回答
  •  臣服心动
    2021-02-20 14:36

    You can use Glob Module as well. It works fine for me!

    var glob = require( 'glob' );  
    var myPath= "/fileFolder/**/*.txt";
    
    glob(myPath, function (er, files) {
        // Files is an array of filenames.
        // Do something with files.
    })
    

提交回复
热议问题